装修问答

如何理解Python装饰器?

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

常陆院尼美 382024-06-16