Populating a list

David Bolen db3l at fitlinxx.com
Mon Dec 10 21:30:08 CET 2001


Chris Barker <chrishbarker at attbi.com> writes:

> Python does close the file when it's reference count goes to zero, which
> will happen as soon as that line is done processing. I'm pretty sure it
> is guaranteed, I certainly have never had a problem with it. That's
> what's nice about Python's reference counting scheme.

Note that "Python" the language doesn't guarantee this behavior, but
rather it's an aspect of the current CPython implementation using
reference counting that behaves this way (but Jython doesn't, for
example).

Of course, plenty of people people write code depending on that
behavior and like it, but it's not guaranteed by the language, so if
you want to be absolutely certain of recovering resources such as file
handles, you should explicitly close them when done using them.

--
-- David
-- 
/-----------------------------------------------------------------------\
 \               David Bolen            \   E-mail: db3l at fitlinxx.com  /
  |             FitLinxx, Inc.            \  Phone: (203) 708-5192    |
 /  860 Canal Street, Stamford, CT  06902   \  Fax: (203) 316-5150     \
\-----------------------------------------------------------------------/



More information about the Python-list mailing list