怎样在定义一个对象的时候取得对象的名称,例如:
class TheThing():
def __init__(self):
self.name = str(self) #此处想获得赋值对象的名称
print(self.name)
a = TheThing()
此时想要得到a.name==’a’,该如何实现
怪我咯2017-04-18 09:21:24
It cannot be implemented because TheThing() will be executed first to obtain an instance of TheThing, and then a will be pointed to this instance. a is just a yin and yang. When executing "a=", TheThing's __init__ has already been executed