Problem with __del__

Joel Ricker joejava at dragonat.net
Tue Jan 9 18:17:13 EST 2001


Fredrik Lundh wrote in message <1OJ66.4624$AH6.762498 at newsc.telia.net>...

>python replaces global objects with None during cleanup, in a well-
>defined but somewhat unpredictable (for a human, at least) order:
>
>    http://www.python.org/doc/essays/cleanup.html
>
>if you can, get rid of the destructors (__del__ methods are evil, and
>shouldn't be used in normal programming).
>
>if you really must keep them around, make sure you keep references
>to global objects:
>
>    def __del__(self, dosomething=dosomething):
>        print self.name, dosomething
>        dosomething()
>
>hope this helps!


I guess I could chime in with my question.  What is the proper
implementation of deleting objects once you are done with them.  Thats
probably the one part of the objects section of the tutorial  that I wasn't
sure about. Wouldn't you want a destructor to do things for cleanup or would
just implement it differently like this:

def deleteme(self)
    dosomething();
    del self

Joel "this OOP isn't so hard after all" Ricker
--
I have been Perl-Free for 4 Days, 20 Hours, 27 Minutes, and 38 Seconds.
-----------------------------------------------------------------------
Joel Ricker   joejava at dragoncat.net
  Just Another Python Hacker





More information about the Python-list mailing list