Question about csv writer

Paul McGuire ptmcg at austin.rr._bogus_.com
Mon Mar 20 11:40:46 EST 2006


<tkpmep at hotmail.com> wrote in message
news:1142871879.839865.217700 at i39g2000cwa.googlegroups.com...
> 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
>

Probably because append returns None, not the list you just appended to.

Also, it appears that your append statement is not doing what you want,
appending to [dates[i]] (that is, a temporary list containing a single
element, the list that is the i'th element of dates), when your "working"
example appends directly to dates[i].

Sometimes (usually?) an explicit body of 2 or 3 statements is better than
trying to cram everything into a one-liner...

-- Paul





More information about the Python-list mailing list