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']
标签:csv,python,读写,writer,reader,test,import,CSV,open 来源: https://www.cnblogs.com/CourserLi/p/16701695.html