counting references to an instance
aahz at pythoncraft.com
Wed Feb 4 22:22:26 CET 2004
In article <pan.2004.02.04.21.00.59.322564.7241 at sympatico.ca>,
Brian <balex at sympatico.ca> wrote:
>On Wed, 04 Feb 2004 14:57:59 -0500, Aahz wrote:
>> In article <pan.2004.02.04.18.55.02.385092.6672 at sympatico.ca>, Brian
>> <balex at sympatico.ca> wrote:
>>>Is it possible to get an object to return the number of references there
>>>are to itself?
>>>a = test()
>>>b = a
>>># Should print "2", if I knew the name of the method. print a.refCount()
>> sys.getrefcount(a) will do the trick -- but it will print 3. Can you
>> figure out why?
>Does the instance of test contain a reference to itself?
Nope. Robert Brewer's response explained it.
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code --
not in reams of trivial code that bores the reader to death." --GvR
More information about the Python-list