python学习 __getattr__用法

 1 class Foo():
 2     def __init__(self):
 3         pass
 4 
 5     def __getattr__(self, item):
 6         print(item,)
 7         return self
 8 
 9     def __str__(self):
10         return ''
11 
12 print(Foo().think.diffrent.itcast)
13 
14 执行结果:
15 think
16 diffrent
17 itcast

 

posted on 2019-09-08 12:21  cherry_ning  阅读(175)  评论(0)    收藏  举报

导航