Question about csv writer

tkpmep at hotmail.com tkpmep at hotmail.com
Mon Mar 20 11:24:39 EST 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
range(N)]))

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)])
     writer.writerow(x)

It works like a charm.

Question: Why does the first form not work?

Thomas Philips




More information about the Python-list mailing list