Scanning a file

Paul Rubin http
Sun Oct 30 00:18:09 CEST 2005

"Paul Watson" <pwatson at> writes:
> How could I identify when Python code does not close files and depends on 
> the runtime to take care of this?  I want to know that the code will work 
> well under other Python implementations and future implementations which may 
> not have this provided. 

There is nothing in the Python language reference that guarantees the
files will be closed when the references go out of scope.  That
CPython does it is simply an implementation artifact.  If you want to
make sure they get closed, you have to close them explicitly.  There
are some Python language extensions in the works to make this more
convenient (PEP 343) but for now you have to do it by hand.

More information about the Python-list mailing list