python 读写 CSV
写入 CSV
1. 写入多行(writerows
)
import csv
with open('test.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerows(["6","6","6"])
test.csv 内容如下:
6
6
6
2. 写入一行(writerow
)
import csv
with open('test.csv', 'w', newline='') as f:
writer = csv.writer(f)
writer.writerow(["6","6","6"])
test.csv 内容如下:
6,6,6
读取 CSV
import csv
with open('test.csv', newline='', encoding='utf-8') as f:
reader = csv.reader(f)
for row in reader:
print(row)
# ['6', '6', '6']
喜欢划水摸鱼的废人