Python equivalent of C++'s virtual destructors?
Alex Martelli
alex at magenta.com
Tue Aug 1 07:29:31 EDT 2000
"Erik Max Francis" <max at alcyone.com> wrote in message
news:3985CAB9.4928BDDE at alcyone.com...
> I have a class which has to do cleanup when it goes out of scope (and so
> has a __del__ method), but which is also going to be derived and its
> subclasses may also need to do class-specific things on destruction as
> well. What is the accepted way of handling this situation? The
> solution which presents itself most easily is simply to explicitly call
> the destructor of the base class in the derived class:
I believe this is the normal approach.
> However, I distinctly recall reading somewhere that explicitly calling a
> __del__ method for a class is a big no-no.
I believe this restriction is meant to apply to 99+% of the cases, the
odd-case out being exactly this one: a derived class's __del__ needing
to call the parents'.
Alex
More information about the Python-list
mailing list