I would like to know if this is possible/how it is possible.
I have a Python object class:
class myClass(object):
def __init__(self):
...do something
Then I create an instance of that object:
myObjectClass = myClass()
From within myClass, is it possible to get the "name" of the variable (myObjectClass) as a string?
Thanks, Adam
No, it isn't possible, in any reasonable manner, and also multiple variables may point to the same object. It's also not possible at all in respect of local variables. Whatever problem you're actually trying to solve, this is the wrong way to go about it.
Also, sort out your understanding of the difference between an object or instance and a class.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With