[Tutor] newb help reading lines from csv
Joel Goldstick
joel.goldstick at gmail.com
Mon Oct 22 21:30:44 CEST 2012
On Mon, Oct 22, 2012 at 3:20 PM, Dewhirst, Rob <robdewhirst at gmail.com> wrote:
> import csv
> ifile = open('test.csv', "r")
> reader = csv.reader(ifile)
> for row in reader:
> print row
> for row in reader:
> print row
> ifile.close()
>
> This is a simplified version of what I am trying to do - loop through
> a CSV file twice. Why does the second for loop not execute at all?
> The first one prints the rows of the file just fine.
> _______________________________________________
> Tutor maillist - Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor
You need to close the file and re open to iterate again. You can't
reset the iterator back to the beginning without closing and
re-opening
--
Joel Goldstick
More information about the Tutor
mailing list