reference counting and file objects

Paul Rubin http
Tue May 17 14:58:24 EDT 2005


John Reese <jtr at ofb.net> writes:
> Consider the function above.  Do I need the fp.close(), or will the
> file be closed automatically when fp goes out of scope and its
> reference count drops to zero?

In CPython, fp gets closed when it leaves scope.  In other
implementations you may need try-finally.  There's been occasional
discussion of possible new Python control blocks to make this easier.



More information about the Python-list mailing list