装饰器重点内容就只有两个:
最重要第一个:双层装饰器
def outter(func):
def wrapper(args,**kwargs):
wrapper是未来要运行的函数
此处加功能此处加功能
res=func(args,**kwargs)
return res
return wrapper
@outter
def hanshu():
pass
装饰器不需要追求他的原理,多用会用即可。
三层装饰器:给双层装饰器加参数的
def sanceng(engine):
def outter(func):
def wrapper(args, **kwargs):# wrapper是未来要运行的函数
# 加功能
print(engine)
res = func(args, **kwargs) # func是被装饰的函数
return res
return wrapper
return outter
@sanceng('file')
def shopping():
pass