该方法以iterable作为参数。您的结果集必须是列表(列)的列表(行)。csv.writer
writerow
csvwriter.writerow(row)
将 行 参数写入编写者的文件对象,并根据当前方言格式化。
执行以下任一操作:
import csv
RESULTS = [
['apple','cherry','orange','pineapple','strawBerry']
]
with open('output.csv','wb') as result_file:
wr = csv.writer(result_file, dialect='excel')
wr.writerows(RESULTS)
要么:
import csv
RESULT = ['apple','cherry','orange','pineapple','strawBerry']
with open('output.csv','wb') as result_file:
wr = csv.writer(result_file, dialect='excel')
wr.writerow(RESULT)