does python have useless destructors?
Manlio Perillo
NOmanlio_perilloSPAM at libero.it
Tue Jun 15 06:41:27 EDT 2004
On Wed, 9 Jun 2004 20:40:11 +0000 (UTC), "Michael P. Soulier"
<msoulier at digitaltorque.ca._nospam> wrote:
> [...]
Hi.
Since __del__ isn't really 'useful', *maybe* a better solution is to
add another special method for classes, ad example a __finalize__
method.
Such method, if present, *will* be called during stack unwinding.
So, in __finalize__ one can release 'external' resources.
class file:
__init__(self, ...): ...
__finalize__(self): self.close()
...
Another useful addition could be to add a 'block' statement:
a_file = '...'
block:
f = open(a_file)
f.write(...)
As an example, block can be supposed to be equivalent to:
block:
statement
=>
def __block()
statement
__block()
Regards Manlio Perillo
More information about the Python-list
mailing list