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

Marc 'BlackJack' Rintsch bj_666 at gmx.net
Wed Jan 10 02:55:30 EST 2007


In <mailman.2514.1168408718.32031.python-list at python.org>, Julio Biason
wrote:

> 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?

Only when the GC destroys it.

Ciao,
	Marc 'BlackJack' Rintsch



More information about the Python-list mailing list