Python使用CSV模块,当写入多行时中间出现空行解决
问题: 当使用python csv库写入时,发现当写入多行是,每两行中间都有空行,解决办法如下
with open("test.csv",'w') as f: writer=csv.writer(f) writer.writerow([line1]) writer.writerows([line2])
解决方法:
with open("test.csv",'w', newline="") as f: writer=csv.writer(f) writer.writerow([line1]) writer.writerows([line2])
解决办法就是写入后面加上newline=''
特此记录!!!!