Beginner's Question (or bug in python?)

Remco Gerlich scarblac at pino.selwerd.nl
Tue Apr 24 11:06:03 EDT 2001


Rolf Magnus <ramagnus at zvw.de> wrote in comp.lang.python:
> Rainer Deyke wrote:
> 
> > When a module is destroyed (because the program terminates), the order in
> > which its contents are removed is arbitrary.
> 
> Well, I only have one object, the one that x points to.
> So is it possible that when the module is deleted, the base class of my 
> object doesn't exist any more when the destructor is called?
> Are classes also objects in python?

Yes, classes are also objects. And so are modules.

It seems that the variable Fred was already None, so maybe the module's
namespace had already been emptied, or something like that. The class still
exists (try printing self.__class__.__bases__). Calling the
parent's __del__ with

       self.__class__.__bases__[0].__del__(self)
       
still worked. For some reason this is pretty magical. If you need __del__
functions at program end, you can assume almost nothing. There is no good
way for Python to decide on an order to delete things, so the order is
arbitrary. Try not to depend on __del__ methods much.

-- 
Remco Gerlich



More information about the Python-list mailing list