Class destructors

Gilles Lenfant glenfant.nospam at bigfoot.com
Wed Jun 20 06:40:41 EDT 2001


Just add a "__del__(self):" method in your class to make a custom cleanup
(close file, socket...).

It's perhaps what you need.
More info at...
http://www.python.org/doc/current/ref/customization.html


--Gilles

"Graham Ashton" <graham at coms.com> a écrit dans le message news:
Se_X6.1458$h45.9288 at news.uk.colt.net...
> I understand that Python doesn't have the equivalent of the DESTROY()
> method in Perl, as the tutorial says:
>
>   "There are no special constructors or destructors."
>
> Surely there is a way of executing some code before the garbage collector
> destroys the object though? Can anybody give me some pointers?
>
> Specifically, I want to close a socket when I've finished with my object
> without having to do so explicitly from with the program that uses the
> object.
>
> Thanks.
>
> --
> Graham





More information about the Python-list mailing list