csv iterator question

davidj411 davidj411 at gmail.com
Fri May 23 16:36:55 EDT 2008


When you save an open file to a variable, you can re-use that variable
for membership checking.
it does not seem to be that way with the csv.reader function, even
when set to a variable name.

what is the best way to store the open CSV file in memory or do i need
to open the file each time?

example of open method on file object:
fhandle=open(filename).readelines()

example of csv.reader method:
reader = csv.reader(open(csvfilename))


here are my results:
>>> reader = csv.reader(open('export.csv'))
>>> for line in reader:
...  print line


<lots of data on page...>

but when i try to iterate through it again, it appears to print
nothing (no error either). the file is exhausted?

>>> for line in reader:
...  print line
...

do i need to seek() the beginning of this file object ? any help is
greatly appreciated here.



More information about the Python-list mailing list