Re: Context manager for files vs garbage collection

2008-06-17 Thread Sebastian "lunar" Wiesner
Floris Bruynooghe <[EMAIL PROTECTED]>: > I was wondering when it was worthwil to use context managers for > file. Consider this example: > > def foo(): > t = False > for line in file('/tmp/foo'): > if line.startswith('bar'): > t = True > break > return

Re: Context manager for files vs garbage collection

2008-06-16 Thread Benjamin
On Jun 16, 8:24 am, Bruno Desthuilliers wrote: > > IIRC (please someone correct me if I'm wrong), proper release of file > resources as soon as the file object gets out of scope is not garanteed > in the language spec and is implementation dependant. Right. Resources are freed in CPython right af

Re: Context manager for files vs garbage collection

2008-06-16 Thread Bruno Desthuilliers
Floris Bruynooghe a écrit : Hi I was wondering when it was worthwil to use context managers for file. Consider this example: def foo(): t = False for line in file('/tmp/foo'): if line.startswith('bar'): t = True break return t What would the benefit

Context manager for files vs garbage collection

2008-06-16 Thread Floris Bruynooghe
Hi I was wondering when it was worthwil to use context managers for file. Consider this example: def foo(): t = False for line in file('/tmp/foo'): if line.startswith('bar'): t = True break return t What would the benefit of using a context manager be