closing file opened by csv reader

M

Maxim Khesin

How about


f = open('bla')
csv_reader = reader(f)
for row in csv_reader:
process(row)
f.close()

?
 
P

Paul Phillabaum

I'd like to close the file the "reader" opens, but I can't figure out how to
reference it.

example:
reader2=csv.reader(file('blah.csv'))

if reader2 was a normal file, I would do "reader2.close()" but that doesn't
work.

I won't show any of the more wacky attempts I made based on my limited
experience as they'd just reveal my total ignorance of this part of python.
I did look through the dictionary for the reader object but couldn't find
what I needed.

Thanks!

Paul
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top