回答編集履歴
2
変更
test
CHANGED
@@ -62,7 +62,7 @@
|
|
62
62
|
|
63
63
|
f_in = open(path, "r", encoding="utf-8")
|
64
64
|
|
65
|
-
f_out = open(dst_filename, 'w', encoding='utf-8')
|
65
|
+
f_out = open(dst_filename, 'w', encoding='utf-8', newline='') # can110様のご指摘をうけて改善
|
66
66
|
|
67
67
|
reader = csv.DictReader(f_in)
|
68
68
|
|
1
例を増やした
test
CHANGED
@@ -41,3 +41,39 @@
|
|
41
41
|
|
42
42
|
|
43
43
|
[Pythonでcsvファイルにデータを書き込みをする基本中の基本](https://tonari-it.com/python-csv-writer-writerow/#toc3)
|
44
|
+
|
45
|
+
|
46
|
+
|
47
|
+
```python
|
48
|
+
|
49
|
+
import csv
|
50
|
+
|
51
|
+
import os.path
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
dirname = os.path.dirname(__file__)
|
56
|
+
|
57
|
+
path = os.path.join(dirname,"test.csv")
|
58
|
+
|
59
|
+
dst_filename = sys.argv[1]
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
f_in = open(path, "r", encoding="utf-8")
|
64
|
+
|
65
|
+
f_out = open(dst_filename, 'w', encoding='utf-8')
|
66
|
+
|
67
|
+
reader = csv.DictReader(f_in)
|
68
|
+
|
69
|
+
writer = csv.writer(f_out)
|
70
|
+
|
71
|
+
for line in reader:
|
72
|
+
|
73
|
+
writer.writerow([line["status"], line["user_id"]])
|
74
|
+
|
75
|
+
f_in.close()
|
76
|
+
|
77
|
+
f_out.close()
|
78
|
+
|
79
|
+
```
|