[Tutor] newb help reading lines from csv
Emile van Sebille
emile at fenx.com
Mon Oct 22 21:28:16 CEST 2012
Dewhirst, Rob 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.
The first pass also exhausts the input feed -- you'll need to rewind or
reposition the next line pointer to the start of the file and I suspect
the easiest way is to reopen the file.
Emile
More information about the Tutor
mailing list