How can I see all the variables related to an object?
1 answer
First, get a dictionary of all the variables currently in scope and their values .
d = dict(globals(), **locals())
Then create a list of all references in the dictionary where the value matches the object of interest:
[ref for ref in d if d[ref] is obj]
eg:
A = [1,2,3] B = A C = B d = dict(globals(), **locals()) print [ref for ref in d if d[ref] is C]
output:
['A', 'C', 'B']
+2
source to share