Newbie question: does file("text.txt', "w").write("stuff") ever get closed?

Fredrik Lundh fredrik at pythonware.com
Fri Nov 18 09:20:08 CET 2005


"John Doe" <spamproof at walla.com> wrote:

> In an effort to avoid another potential mistake, I am wondering if the
> anonymous file object/class/thingy that I create when I do file("text.txt',
> "w").write("stuff") gets closed properly on exit or garbage collection or
> something

yes.

> or if I always need to hang on to these things and close them myself.

only if you want to 1) know exactly when the files are closed, or 2) are
using so many files that the garbage collector cannot keep up with you
(this never happens on CPython, but can, at least in theory, happen on
other Python implementations)

</F> 






More information about the Python-list mailing list