destructor not called

Marcin201 marcin201 at
Sun Sep 28 18:00:34 CEST 2008

I have a class which uses a temporary directory for storing data.  I
would like that directory to be removed when the class is no longer
used.  I have tried removing the temporary directory from the class
destructor, however, it was never called.  After I while I traced the
problem to the class having a reference to it's own function.  Here is
a simplified model.
class Foo:
    def __init__(self):
        print "Hello"
        self.f = self.fxn

    def __del__(self):
        print "Bye"

    def fxn(self):
        print "function"

a = Foo()

running python I get

Is this an expected behavior or a bug in python?  If this is expected
any suggestions for working around this.  I would like to avoid having
to call the destructor explicitly.



More information about the Python-list mailing list