如何理解Python装饰器?



                    
                    
丹儿你个丹儿
79084 次浏览 2024-05-03 提问
51

最新回答 (1条回答)

2024-05-03 回答

# 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()就是在函数上加个包装

相关问题

页面运行时间: 0.086827039718628 秒