__getattr__与__getattribute__

class Foo:
    def __init__(self,x):
        self.x=x
    def __getattr__(self, item):
        print("执行的是我----->")
    def __getattribute__(self, item):
        print('不管是否纯在,我都执行--------》')
        raise AttributeError("接口")

f1 = Foo(10)
f1.x
f1.xxxxxxxxxxxx

  

原文地址:https://www.cnblogs.com/huangjinshan/p/6224935.html