class Foo: x=1 def __init__(self,y): self.y=y def __getattr__(self, item): print('----> from getattr:你找的属性不存在') f1=Foo('10') print(f1.y) print(f1.x) print(f1.iyiu) 结果: 10 1 ----> from getattr:你找的属性不存在 None