怎样在定义一个对象的时候取得对象的名称,例如:
class TheThing(): def __init__(self): self.name = str(self) #此处想获得赋值对象的名称 print(self.name) a = TheThing()
此时想要得到a.name==’a’,该如何实现
光阴似箭催人老,日月如移越少年。
Cela ne peut pas être implémenté car TheThing() sera d'abord exécuté pour obtenir une instance de TheThing, puis a sera pointé vers cette instance a n'est qu'un yin et un yang. Lors de l'exécution de "a=", le __init__ de TheThing a déjà été exécuté
Cela ne peut pas être implémenté car TheThing() sera d'abord exécuté pour obtenir une instance de TheThing, puis a sera pointé vers cette instance a n'est qu'un yin et un yang. Lors de l'exécution de "a=", le __init__ de TheThing a déjà été exécuté