class obj(object):
def __init__(self):
self.name = ... # How to set this variable dynaically by using the variable name (on create) or the object name?
var = obj()
print(var.name) # prints "var" (assigned variable name)
print(obj().name) # prints "obj"
Currently, both of them prints “obj”.
How can I set self.name
according to the way the obj
object is created?
New contributor
congtailai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.