Home  >  Article  >  Backend Development  >  python如何实现php的 __call函数实现的功能?

python如何实现php的 __call函数实现的功能?

WBOY
WBOYOriginal
2016-06-06 20:51:391608browse

php的__call函数方法,用在类里可以捕获所有未定义方法的调用。请问在python中有什么方法能实现同类功能。多谢。

回复内容:

php的__call函数方法,用在类里可以捕获所有未定义方法的调用。请问在python中有什么方法能实现同类功能。多谢。

class Foo(object):
    def __getattr__(self, key):
        return lambda:'bar'

f = Foo()
print f.bar()
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn