【发布时间】:2020-08-14 08:55:29
【问题描述】:
下面的代码将完整列表 ['x', 'y', 'z'] 添加为 csv 的单个元素。我想要得到的是行尾的'x'; 'y'; 'z';。怎么样?
import csv
toto = ['x', 'y', 'z']
with open('res.csv', 'w', newline='') as resfile:
reswriter = csv.writer(resfile, delimiter=';')
reswriter.writerow(['Number', 'A', 'B', 'X', 'Y', 'Z']) # header.
reswriter.writerow(['001', 'a', 'b', toto])
【问题讨论】:
-
reswriter.writerow(['001', 'a', 'b'] + toto)