例如列表:list = [‘abc’, ‘def’ , ‘ghi’]
list = ['abc', def'' , 'ghi']
with open("./CVE.csv", "a", newline='', encoding='utf-8') as file:
writer = csv.writer(file ,delimiter=',')
writer.writerow(list)
结果都在同一行:
abc,def,ghi
若是用writer.writerows()方法,结果每个字母都被逗号隔开:
a,b,c
d,e,f
g,h,i
若是想让列表写入csv中按行切出现被逗号分隔的情况,列表应是:
[[‘abc’], [‘def’], [‘ghi’]]
此时用writer.write()方法结果:
[‘abc’], [“def”], [‘ghi’]
使用writer.writerows()方法才是想要的结果:
abc
def
ghi