import csv
with open('data.csv','w') as file:
writer = csv.writer(file)
writer.writerow(['id','name','age'])
writer.writerow(['10001','ZhangSan',18])
writer.writerow(['10002','LiSi','20'])
使用writerrow写入文件总有空行出现
在打开文件的方法里面设置参数:newline=‘’ 即可
import csv
with open('data.csv','w',newline='') as file:
writer = csv.writer(file)
writer.writerow(['id','name','age'])
writer.writerow(['10001','ZhangSan',18])
writer.writerow(['10002','LiSi','20'])
输出的文件没有空行