当getattr与__getattribute__同时出现时:先找__getattribute__,如果抛出异常则执行getattribute
1 class Foo: 2 def __init__(self,x): 3 self.x=x 4 def __getattr__(self, item): 5 print("执行的是我") 6 def __getattribute__(self, item): 7 print("我是ibute") 8 raise AttributeError("哈哈") 9 10 f1=Foo(10) 11 f1.x
__getattribute__(self, item)
时间: 2024-11-03 01:24:09