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. -- https://mail.python.org/mailman/listinfo/python-list