reading csv problem

ajikoe at gmail.com ajikoe at gmail.com
Wed Nov 15 03:00:36 EST 2006


Thank you.


On Nov 15, 1:33 pm, Cameron Walsh <cameron.wa... at gmail.com> wrote:
> aji... at gmail.com wrote:
> > Hello,
>
> > I use csv to take information from file.
> > import csv
> > reader = csv.reader(open('t.csv'))
>
> > for row in reader:
> >     print row # it is perfectly OK
>
> > ---------------------------------------------------------------------
> > But If I use this code I have problem
> > import csv
> > reader = csv.reader(open('t.csv'))
>
> > for row in reader:
> >     print row # it is perfectly OK
> > for row in reader:
> >     print row # it is not printed on the monitor???
>
> > Why does only the first print row work here?
>
> > TIA,
> > ajikoeBecause reader is an iterator and has no means of going back to its
> beginning.
>
> You could make a list out of it:
> lines = list(csv.reader(open('t.csv')))
> for row in lines:
>   print row
> for row in lines:
>   print row
> 
> Hope it helps,
> 
> Cameron.




More information about the Python-list mailing list