Google

星期二, 四月 07, 2009

捕捉一个对象的属性

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

标签:

0 条评论:

发表评论

<< 主页

辽ICP备05003652号
流风洄雪听天籁,轻云蔽日看落花

Powered by Blogger