File Closing Problem in 2.3 and 2.4, Not in 2.5 (Final report)

Julio Biason slow at slowhome.org
Wed Jan 10 00:36:18 EST 2007


[Kinda stealing the thread]

On Tue, Jan 09, 2007 at 09:05:30PM -0300, Gabriel Genellina wrote:
> And do you actually need so many open files simultaneously?
> Try to close them explicitely when you finish working on them - do 
> not rely on GC for closing files. This has *always* been the 
> recomended practice (except maybe, inside a short script that 
> finishes quickly).

If I use a file() in a for, how to I explicitely close the file?

<code>
for line in file('contents'):
   print line
</code>

Would this work like the new 'with' statement or it will only be closed
when the GC finds it?

--
Julio "slow" Biason <slow at slowhome.org>



More information about the Python-list mailing list