CSV Error

JC chalao.adda at gmail.com
Sun Dec 28 07:46:35 EST 2014


On Sun, 28 Dec 2014 06:19:58 -0600, Skip Montanaro wrote:

>> ValueError: I/O operation on closed file
>>
>> Here is my code in a Python shell -
>>
>> >>> with open('x.csv','rb') as f:
>> ...     r = csv.DictReader(f,delimiter=",")
>> >>> r.fieldnames
> 
> The file is only open during the context of the with statement. Indent
> the last line to match the assignment to r and you should be fine.
> 
> Skip <p dir="ltr">> ValueError: I/O operation on closed file<br>
> ><br>
> > Here is my code in a Python shell -<br>
> ><br>
> > >>> with open('x.csv','rb') as f:<br>
> > ...     r = csv.DictReader(f,delimiter=",")<br>
> > >>> r.fieldnames</p>
> <p dir="ltr">The file is only open during the context of the with
> statement. Indent the last line to match the assignment to r and you
> should be fine.</p>
> <p dir="ltr">Skip</p>

I have indented the line. I am working in the shell. The error is still 
there.

Thanks.



More information about the Python-list mailing list