[英]Enumerate lines while printing to to file .CSV PYTHON
我有一个简单的清单清单。 4个列出,每个列出3个值
with open('test2.csv', 'w',) as f2:
f = csv.writer(f2, delimiter= '\t')
header = ["SENSOR", "h1", "h2", "h3"]
f.writerow(header)
for idx, lists in final_list:
f.writerow(lists)
print "IDX:",idx, "LISTS:", lists
“对于idx,final_list中的列表:”发生错误,并显示:
ValueError: too many values to unpack
你不远:-)你只需要:
for idx, lists in enumerate(final_list):
f.writerow(lists)
print "IDX:",idx, "LISTS:", lists
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.