|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
- >>> class C:
- def __getattr__(self, name):
- print(1)
- return super().__getattr__(name)
- def __getattribute__(self, name):
- print(2)
- return super().__getattribute__(name)
- def __setattr__(self, name, value):
- print(3)
- super().__setattr__(name, value)
- def __delattr__(self, name):
- print(4)
- super().__delattr__(name)
-
- >>> c = C()
- >>> c.x
复制代码
像这样 return super().__getattribute__(name) 的语句,调动基类的方法是干啥用的?
那么__getattr__是__getattribute__的父类
他们都属于方法,没有父子类之分,当你 没有特别指明的 类都默认 继承 object 类,也就是基类,基类中有 __getattr__和__getattribute__ 方法
|
|