回答編集履歴
3
解説追加
test
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
+
そりゃあmode='wt'で毎回既存内容破棄してるんだから最後のデータ以外残らないでしょう。wtはwrite textの略でwと挙動は同じです。
|
1
|
-
|
2
|
+
後個人的にcsv.writer.writerowおすすめ。自動で改行してくれる
|
2
3
|
```Python3.10
|
3
4
|
with open('data.csv', 'a',newline='', encoding='utf-8') as fout:
|
4
5
|
writer=csv.writer(fout)
|
2
修正
test
CHANGED
@@ -1,4 +1,6 @@
|
|
1
|
-
追記
|
1
|
+
mode=wtだと毎回上書きになっちゃうのでやっぱり追記の方がいいと思うんですが
|
2
|
-
|
2
|
+
```Python3.10
|
3
|
-
with open(
|
3
|
+
with open('data.csv', 'a',newline='', encoding='utf-8') as fout:
|
4
|
-
|
4
|
+
writer=csv.writer(fout)
|
5
|
+
writer.writerow(data)
|
6
|
+
```
|
1
一応説明を追加。
test
CHANGED
@@ -1,2 +1,4 @@
|
|
1
|
+
追記するなら読み込み専用で開いては駄目ですよ。
|
1
2
|
|
2
3
|
with open(fn, 'a', encoding='Shift_JIS') as file:
|
4
|
+
|