file object: seek and close?

Peter Otten __peter__ at web.de
Thu Sep 18 13:18:01 EDT 2003


Shu-Hsien Sheu wrote:

> Does the seek method would close the file object after using a for loop?
> My program looks like this:
> 
> f = open('somefile', 'r')
> for lines in f:
>     some operations
> f.seek(0)
> 
> for lines in f:
>     other operations
> 
> Python gave me an IOErros saying that the file object is already closed.
> I am now opening the file again under another file object.
> 
> Am I doing something wrong or it's a bug?

The code you posted works here (I substituted "other operations" with "print
lines"). Please reduce your actual code to the minimum that still fails and
repost together with cut and pasted traceback.

Peter




More information about the Python-list mailing list