如何理解Python装饰器?



                    
                    
韩建忠001
45530 次浏览 2024-05-30 提问
137

最新回答 (1条回答)

2024-05-30 回答


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

class Demo(object);hello"

d = Demo()
d

相关问题

页面运行时间: 0.087930917739868 秒