目录:

一、 __getattribute__

二、__str__,__repr__,__format__

三、__doc__

四、__module__和__class__

一、 __getattribute__                                                               

 1 class Foo:
 2     def __init__(self,x):
 3         self.x=x
 4 
 5     def __getattr__(self, item):
 6         print('执行的是我')
 7         # return self.__dict__[item]
 8 
 9 f1=Foo(10)
10 print(f1.x)
11 f1.xxxxxx #不存在的属性访问,触发__getattr__
12 
13 回顾__getattr__
回顾__getattr__

相关文章:

  • 2021-07-30
  • 2021-11-09
  • 2021-09-09
  • 2021-07-06
  • 2022-12-23
  • 2022-12-23
  • 2021-09-22
猜你喜欢
  • 2021-09-11
  • 2022-12-23
  • 2021-07-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案