[英]List to CSV Writer Python
我正在嘗試寫入CSV(我已經閱讀了docs /大多數其他線程)。 但對我而言,僅將最后一行復制到CSV。 這就是我所擁有的
def writetocsv(l):
#convert the set to the list
b = list(l)
#print b #checking print b, it prints all values of b
with open("eggs.csv",'wb') as f:
w = csv.writer(f)
w.writerows(b)
我的輸入(b)是
[a,b,c]
我對CSV的期望是
a.
b,
c
我得到的是
c
def writetocsv(l):
#convert the set to the list
b = list(l)
#print b #checking print b, it prints all values of b
with open("eggs.csv",'wb') as f:
w = csv.writer(f)
for value in b:
w.writerow(value)
使用for循環遍歷列表b
,使用writerow
寫入單個value
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.