make objetcs 'commit suicide'

Ype Kingma ykingma at accessforall.nl
Sun Jan 12 15:57:37 CET 2003


polux wrote:

> class a:
> def go(self):
> self.__del__            # or del(self)

I suppose you mean:

    def go(self):
        self.__del__()

?

> 
> 
> and then
> b=a()
> b.go()
> 
> 
> b is not destructed

Since b is defined at module level

del b

instead of b.go() might be more appropriate.
Note that "del x"  does not call x.__del__(),
it only removes the reference named x from the namespace.
In case the object referred to has it's reference count
go to zero because of the del statement, the __del__
method of the object _may_ be called.

Regards,
Ype


-- 
email at xs4all.nl




More information about the Python-list mailing list