Question about csv writer

tkpmep at tkpmep at
Mon Mar 20 17:24:39 CET 2006

I expected the following code to work:

f = file(fn,"wb")
writer = csv.writer(f)
for i in range(IMax):
     writer.writerow([dates[i]].append([ReturnHistories[j][i] for j in

but instead i got the following error message:
Error: sequence expected

However, if i modify the code to read
writer = csv.writer(f)
for i in range(IMax):
    x = dates[i]
    x.append([ReturnHistories[j][i] for j in range(N)])

It works like a charm.

Question: Why does the first form not work?

Thomas Philips

More information about the Python-list mailing list