如何理解Python装饰器?



                    
                    
花蜜honey
10002 次浏览 2024-05-15 提问
96

最新回答 (1条回答)

2024-05-15 回答

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

相关问题

页面运行时间: 0.1230731010437 秒