when will the file be closed

Fredrik Lundh fredrik at pythonware.com
Sun Apr 24 14:33:42 EDT 2005


"Mage" <mage at mage.hu> wrote:

> The question is above: when will these file be closed?
>
> for s in file('/etc/passwd'):
>     print s
>
> file('/home/mage/test.txt','w').write('foo')

when the interpreter gets around to it.

if you want to make sure that a file is closed at a given point in
your program, you have to close it yourself.

for more on this, read the fine manual:

    http://docs.python.org/ref/objects.html

</F>






More information about the Python-list mailing list