0

python 有没有像 PHP __call 一样的方法

martina created at5 years ago view count: 163
report
回复
0
def __getattr__(self, attr):
    print("Calling __getattr__: "+attr)
    if hasattr(self.child, attr):
        def wrapper(*args, **kw):
            print('called with %r and %r' % (args, kw))
            return getattr(self.child, attr)(*args, **kw)
        return wrapper
    raise AttributeError(attr)
5 years ago 回复