回答編集履歴
3
修正
test
CHANGED
@@ -50,9 +50,9 @@
|
|
50
50
|
|
51
51
|
```Python
|
52
52
|
|
53
|
-
with open('src.csv') as fin, \
|
53
|
+
with open('src.csv', newline='') as fin, \
|
54
54
|
|
55
|
-
open('dst.csv', 'w') as fout:
|
55
|
+
open('dst.csv', 'w', newline='') as fout:
|
56
56
|
|
57
57
|
|
58
58
|
|
2
追記
test
CHANGED
@@ -39,3 +39,35 @@
|
|
39
39
|
|
40
40
|
|
41
41
|
実行例: [Wandbox](https://wandbox.org/permlink/JGWeJ4KJrtBzQp1f)
|
42
|
+
|
43
|
+
|
44
|
+
|
45
|
+
コメントを受けて
|
46
|
+
|
47
|
+
---
|
48
|
+
|
49
|
+
合法なcsv形式なのですね。
|
50
|
+
|
51
|
+
```Python
|
52
|
+
|
53
|
+
with open('src.csv') as fin, \
|
54
|
+
|
55
|
+
open('dst.csv', 'w') as fout:
|
56
|
+
|
57
|
+
|
58
|
+
|
59
|
+
reader = csv.reader(fin)
|
60
|
+
|
61
|
+
writer = csv.writer(fout)
|
62
|
+
|
63
|
+
|
64
|
+
|
65
|
+
for line in reader:
|
66
|
+
|
67
|
+
writer.writerow(line[2:])
|
68
|
+
|
69
|
+
|
70
|
+
|
71
|
+
# 上記ループを丸ごと writer.writerows(line[2:] for line in reader) に置き換えても可
|
72
|
+
|
73
|
+
```
|
1
追記
test
CHANGED
@@ -32,6 +32,10 @@
|
|
32
32
|
|
33
33
|
elems = line.strip('[]').split(',')
|
34
34
|
|
35
|
-
print(elems[2:], file=fout)
|
35
|
+
print(f'[{",".join(elems[2:])}]', file=fout)
|
36
36
|
|
37
37
|
```
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
実行例: [Wandbox](https://wandbox.org/permlink/JGWeJ4KJrtBzQp1f)
|