when should I explicitly close a file?
Alf P. Steinbach
alfps at start.no
Thu Apr 22 01:48:47 EDT 2010
* Lawrence D'Oliveiro:
> In message <4bc9aadb$1 at dnews.tpgi.com.au>, Lie Ryan wrote:
>
>> Since in python nothing is guaranteed about implicit file close ...
>
> It is guaranteed that objects with a reference count of zero will be
> disposed.
Only in current CPython.
> In my experiments, this happens immediately.
Depends what you mean, but even in current CPython destruction of a local can be
postponed indefinitely if a reference to the stack frame is kept somewhere.
And that happens, for example, when an exception is raised (until the handler
completes, but it doesn't necessarily complete for a Very Long Time).
Cheers & hth.,
- Alf
More information about the Python-list
mailing list