davidj411 wrote:

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()
>>> fhandle = open('c:/temp/08-02024.csv').readlines()
>>> type(fhandle)
<type 'list'>
>>> len(fhandle)
381

fhandle is a list containing the contents of the file, not a file handle -- that's why you can easily re-use it.

example of csv.reader method:
reader = csv.reader(open(csvfilename))
Try this instead:
>>>reader  = csv.reader(open('c:/temp/08-02024.csv'))
>>> contents = [line for line in reader]
>>> type(contents)
<type 'list'>
>>> len(contents)
381

You still get a list that you can easily use, that has gone through the csv routines.

Hope this helps.
--
Ethan

--
http://mail.python.org/mailman/listinfo/python-list

Reply via email to