ValueError: I/O operation on closed file

Rustom Mody rustompmody at gmail.com
Thu May 26 02:17:03 EDT 2016


On Thursday, May 26, 2016 at 11:17:56 AM UTC+5:30, San wrote:
> On Wednesday, May 25, 2016 at 6:00:07 PM UTC+5:30, San wrote:
> > Hi Gorup,
> > 
> > why i am getting "ValueError: I/O operation on closed file" this error.
> > Pls let me know.
> > 
> > Thanks in Advance.
> > san
> 
> Hello,
> Following is the code i used.
> 
> def test_results(filename):
>     import csv
>     with open(filename,"rU") as f:
>      reader = csv.reader(f,delimiter="\t")
>      result = {}
>     for row in reader:
>         key = row[0]
>         if key in result:
>             result[row[0]].append(row[1])
>         else:
>             result[row[0]] = key
>         result[key]=row[1:]
>     print result
> 
> filename ='filename.csv'
> test_results(filename)


I think your for needs to be indented in the with



More information about the Python-list mailing list