does python have useless destructors?

Tim Bradshaw tfb+google at tfeb.org
Mon Jun 14 14:38:20 EDT 2004


Peter Hansen <peter at engcorp.com> wrote in message news:<u72dnUZjC7EJmlfdRVn-hQ at powergate.ca>...

> Yes, it's certain to be safe (barring multithreaded stuff
> rebinding 'myfile' in between, which is irrelevant to the
> discussion).  Are you perhaps concerned that the open itself
> might fail?  If so, it needs its own try/except block, as I
> noted elsewhere.  The finally is only need *if* the open
> succeeds, but unless you insert code between open() and
> 'try', it's safe.

Yes, I think it is safe: I was thinking from the point of view of a
Lisp macro implementor, where you have to deal with a lot of more
general issues (for instance multiple bindings, which essentially
insert code between the open() and the try, and user reassignments,
which mean that the variable binding vanishes, which you need to cope
with as well. Getting a *general* version of this correct (which is
what I understood the original poster to be asking about) is hard to
do, but that's not a problem for a language without macros.

--tim



More information about the Python-list mailing list