CSV Error
JC
chalao.adda at gmail.com
Sun Dec 28 07:49:00 EST 2014
On Sun, 28 Dec 2014 14:41:55 +0200, Jussi Piitulainen wrote:
> Skip Montanaro writes:
>
>> > 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.
>
> Or, don't use "with" when experimenting in the shell.
>
> >>> import csv f = open('x.csv')
> >>> r = csv.DictReader(f, delimiter = ',')
> >>> r.fieldnames
> ['Foo', 'Bar']
> >>>
Yes, Thanks. It's fixed.
Thanks.
More information about the Python-list
mailing list