Python language problem

Steve Holden steve at
Wed Jun 7 15:09:36 CEST 2006

ripley wrote:
> Boris Borcic wrote:
>>ripleyfu at wrote:
>>>>>>class A:
>>>...   pass
>>>>>>a = A()
>>>>>>b = a
>>>>>>del b
>>><__main__.A instance at 0x00B91BC0>
>>>I want to delete 'a' through 'b', why It does't?
>>>How can I do that?
>>del a,b
> But 'b' is also deleted, i want use 'b' to delete 'a', 'b' is exists.
You can't do what you want to do.

Python names are independent references to objects. The "del" statement 
deletes a name from a namespace (or an item from a structure), and 
cannot be used to delete all references to a given object. In general 
there's no way to delete a referenced object - we normally rely on the 
implementation (in CPython reference counting plus garbage collection, 
in other implementations just plain garbage collection) to perform the 
deletion when no live references to an object remain.

Perhaps you'd like to explain *why* you find a need to do this (in other 
words, what's your use case)?

Weak references are one possibility that might help you, but without 
knowing your real requirements it's difficult to be more helpful.

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd
Love me, love my blog
Recent Ramblings

More information about the Python-list mailing list