如何理解Python装饰器?
最新回答 (1条回答)
# hello=inject_check(hello)########################## class Demo(object):# print " d = Demo()d: def my_method(*args);hello": print " return my_method############################ #class Demo(object):# def hello(self): print "before": @inject_check def hello(self);hello",如上面代码中的hello函数加上@inject_check装饰器; method(*args) print "def inject_check(method),等价于将函数hello重新赋值;after".hello()就是在函数上加个包装