【1701H1】【穆晨】【180118】第100天总结

__getattr__(self,name):定义当用户试图获取一个不存在的属性时的行为

__getattribute__(self,name)定义当该类的属性被访问时的行为

__setattr__(self,name,value)定义当一个属性被设置时的行为

__delattr__(self,name)定义当一个属性被删除时的行为

__getattr__,__getattribute__,__setattr__,delattr_

在A类里没x的属性,所以先调用getattribute在调用getattr,给x赋值,调用setattr,访问x则先调用getattribute,然后给出属性值

__getattr__,__getattribute__,__setattr__,delattr_

else操作里不能用赋值操作比如说:self.name = value,会走死循环,线走init赋值操作会走setattr,然后else这又是辅助,然后导致死循环


相关文章: