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

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

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


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

f = Foo()
print f.bar()
【热门文章】
【热门文章】