尝试使用以下命令将列表写入csv文件:
import csv
with open('filename.csv', 'w', newline='') as csvfile:
wr = csv.writer(csvfile, quoting=csv.QUOTE_ALL)
wr = csv.writerow(list)
返回错误:
module 'csv' has no attribute 'writerow'
非常感谢任何帮助。
答案 0 :(得分:1)
您必须在writerow()
- 实例上致电writer
,而不是csv
:
来自the documentation的Straigth:
import csv with open('eggs.csv', 'w', newline='') as csvfile: spamwriter = csv.writer(csvfile, delimiter=' ', quotechar='|', quoting=csv.QUOTE_MINIMAL) spamwriter.writerow(['Spam'] * 5 + ['Baked Beans']) spamwriter.writerow(['Spam', 'Lovely Spam', 'Wonderful Spam'])