counting references to an instance
Brian
balex at sympatico.ca
Wed Feb 4 16:01:03 EST 2004
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?
>>
>>Ex:
>>
>>class test(object):
>> pass
>>
>>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?
Brian.
More information about the Python-list
mailing list