I understand that you should never use variable names within the program, but I am using is strictly for debug purposes and would like to convey the name of the variable to the user for readability.
I have a file like this:
class MyClass(object):
def __init__(self):
pass
def foo(msg=""):
debug("Called from the %s instance.") #quazi-print function that only prints when a DEBUG variable is True.
print(msg)
m = MyClass()
m.foo("Test")
I would like to retrieve the m
instance variable name from within the class itself. Though this is merely an example file, I am using it to convey to the user that a raw socket has been created at a certain attribute within an instance variable, and would like to show where it is (i.e. New socket at m.socket
)
Is this feasible with Python?