On Tue, Jan 5, 2010 at 4:06 PM, Luhmann <[email protected]> wrote:
>
> When there are no more references to an open file object, will it close, or 
> the file will just remain open, forever unreachable?

When an open file object is garbage-collected it will be closed. In
current versions of CPython GC happens when there are no more
references to an object but other versions of Python (Jython,
IronPython) have different behaviour. There is no guarantee that an
object will ever be GDed.

My recommendation: for production code, explicitly close files. A
'with' block is the easiest way to do this. For quick-and-dirty code
running under CPython, don't worry about it. (Though I admit to being
paranoid enough to always explicitly close a file that is open for
writing.)

Kent
_______________________________________________
Tutor maillist  -  [email protected]
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor

Reply via email to