捕捉一个对象的属性
python , __getattr__
捕捉一个对象的属性
>>> class F:
... def __getattr__(self,attr):
... if attr=='abc':
... return "got it !"
...
>>> f= F()
>>> f.abc
'got it !'
http://www.okpython.com/bbs/thread-696-1-1.html
捕捉一个对象的属性
>>> class F:
... def __getattr__(self,attr):
... if attr=='abc':
... return "got it !"
...
>>> f= F()
>>> f.abc
'got it !'
http://www.okpython.com/bbs/thread-696-1-1.html
标签: Python

0 条评论:
发表评论
<< 主页