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?
It is not possible to find all references to a given object in Python. It is not even possible to find all objects or all references in Python. (The CPython function gc.get_objects
does this, but it is not portable across Python implementations.)
You can use dir()
or locals()
to find all variables that exist at some scope in the program. But if objects have been defined in other places, you could miss them with this method.