This thread discusses how to get the name of a function as a string in Python: How to get a function name as a string?
How can I do the same for a variable? As oppose
I don't believe this is possible. Consider the following example:
>>> a = [] >>> b = a >>> id(a) 140031712435664 >>> id(b) 140031712435664
The a and b point to the same object, but the object can't know what variables point to it.
a
b