版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_36869808/article/details/87908719
笔记
1.读写步骤
1.导入模块
import csv
2.读
with open('xxx.csv',encoding="utf-8") as f:
reader=csv.DictReader(f)
for raw in reader:
print(row)
3.写
with open("xxx.sxv","w",encoding="utf-8") as f:
writer=csv.DicWriter(f.fieldnames=['a','b'])
writer.writerows(data)
2.解决csv写入空一行的办法
with open("save.csv","w",encoding="utf-8",newline='') as f:
加上 newline=""就可以了
原因:https://blog.csdn.net/pfm685757/article/details/47806469