[Tutor] writing csv files

Alan Gauld alan.gauld at btinternet.com
Sat May 22 10:27:47 CEST 2010


"prasad rao" <prasadaraon50 at gmail.com> wrote

> I got a problem writing csv file.

I can't help with that specifically but...

> for x in csvr:
> ...    y=lambda x: 
> ''.join([x.split()[3],x.split()[-3],x.split()[-6]])
> ...    csvw.write(y)

lambdas are intended for anonymous functions so if you
are not going to pass the lambda expression directly
but assign it to a name, then it would be better to take
the definition outside the loop and only do it once.

def y(x): return ''.join([x.split()[3],x.split()[-3],x.split()[-6]])
for x in csvr:
      csvw.write(y)

> Traceback (most recent call last):
>  File "<stdin>", line 3, in <module>
> AttributeError: '_csv.writer' object has no attribute 'write'

But I can't answer this bit, sorry.

Alan G 




More information about the Tutor mailing list