Retrieving the list of references to an object in Python

后端 未结 7 1250
栀梦
栀梦 2020-12-04 01:29

All:

a = 1
b = a
c = b

Now I want to get a list of object 1 tagged, which is [a, b, c]. How could I do this?

7条回答
  •  借酒劲吻你
    2020-12-04 02:26

    As you can see, it's impossible to find them all.

    >>> sys.getrefcount(1)
    791
    >>> sys.getrefcount(2)
    267
    >>> sys.getrefcount(3)
    98
    

提交回复
热议问题