首页 > 装修问答 > 装饰 > 如何理解Python装饰器?

如何理解Python装饰器?

浏览次数:1822|时间:2024-04-26

热门回答

2024-04-25二三子钩

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

186