Reputation: 719
I am trying to write to CSV (i have read the docs/most other threads). but for me only the last line is copied to CSV. This is what I have
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)
My input(b) is
[a,b,c]
What I expect on CSV is
a.
b,
c
What I get is
c
Upvotes: 0
Views: 358
Reputation: 26667
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)
Use a for loop to iterate through the list b
, write the individual value
using writerow
Upvotes: 2