In Python, an object is automatically destroyed once the references to it are no longer in use, or when the Python script completes execution. A destructor is a special function which allows you to execute commands immediately prior to the destruction of an object. You do not usually need to define a destructor - but if you want to see what it looks like, take a look at this: Note that a destructor must always be called __del__() Here's a demonstration of how to use it: And with multiple murder on my hands, it's now time to bid you goodbye. If you're interested in the more arcane aspects of Python's OO capabilities - operator overloading, private and public variables, and so on - you should consider visiting the following sites: The official Python tutorial, at http://www.python.org/doc/current/tut/node11.html The Python Cookbook, at http://aspn.activestate.com/ASPN/Cookbook/Python The Vaults of Parnassus, at http://www.vex.net/parnassus/ Python HOWTOs, at http://py-howto.sourceforge.net/ The Python FAQ, at http://www.python.org/doc/FAQ.html Until next time...stay healthy! Note: All examples in this article have been tested on Linux/i586 with Python 1.5.2. Examples are illustrative only, and are not meant for a production environment. YMMV!\n
blog comments powered by Disqus |