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">&gt; ValueError: I/O operation on closed file<br>
> &gt;<br>
> &gt; Here is my code in a Python shell -<br>
> &gt;<br>
> &gt; &gt;&gt;&gt; with open(&#39;x.csv&#39;,&#39;rb&#39;) as f:<br>
> &gt; ...     r = csv.DictReader(f,delimiter=&quot;,&quot;)<br>
> &gt; &gt;&gt;&gt; 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.
-- 
https://mail.python.org/mailman/listinfo/python-list

Reply via email to