strange behaviour at termination time

Michael Hudson Michael.Hudson at p98.f112.n480.z2.fidonet.org
Thu Jul 1 05:14:13 EDT 1999


From: Michael Hudson <mwh21 at cam.ac.uk>

Ovidiu Predescu <ovidiu at cup.hp.com> writes:

> Greg Ewing wrote:
> 
> > To avoid problems like this, you have to design
> > your __del__ methods so that they can do their
> > work without having to refer to any module-level
> > names at the time they are called. One way is
> > to use the default-argument trick:
> > 
> > class B (A) :
> >     def __del__ (self, A = A) :
> >         A.__del__ (self)
> 
> Can you explain why this trick works? When are the default arguments
> stored in the method instance? I guess this happens when the method
> instance for __del__ is created by the interpreter, right?

Yup, that's it. If you want to find out about these things, read the
language reference or import rlcompleter and bash the completion key a
lot. I this case you'll find

B.__del__.im_func.func_defaults

which will contain something like

<class A at xxxx in xxx>

HTH
Michael
 
> Thanks,
> -- 
> Ovidiu Predescu <ovidiu at cup.hp.com>
> http://www.geocities.com/SiliconValley/Monitor/7464/




More information about the Python-list mailing list