[英]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.