10 总结
总结 p156
基本装饰器(更重要)占比80%
def x1(func):
def inner(*args,**kwargs):
data = func(*args,**kwargs) # 执行原函数并获取返回值
return data
return inner
@x1
def index():
print(123)
index()
带参数的装饰器
def x(counter):
def wrapper(func):
def inner(*args,**kwargs):
data = func(*args,**kwargs) # 执行原函数并获取返回值
return data
return inner
return wrapper
@x(9) #先执行
def index():
pass