>>> a = test(1)
Success
>>> del a
Delete
>>> b = test(0)
Exception
>>> b
<test instance at 20067dc8>
>>> del b
>>> b
Traceback (innermost last):
File "<stdin>", line 1
NameError: b
>>> dir()
['_', '__name__', 'test']
>>>
>>> c = test( 0.0 )
Delete
Exception
Note that the delete is deferred.
After I tried this test, I read Guido's reply that explains why
there is still a lingering reference to self.
The next exception from 'c' clears the saved reference from 'b'
and b's __del__ method is finally called.
And a while back, in answer to another "why isn't '__del__' being
called" question, I posted a partial explaination of reference
counting and 'del' in Python: i.e. 'del' doesn't necessarily execute
__del__ - it decrements the objects reference count, and when the
reference count goes to zero, __del__ is called and then object is
actually deleted.
- Steve Majewski (804-982-0831) <sdm7g@Virginia.EDU>
- UVA Department of Molecular Physiology and Biological Physics