'''标签:wrapper2,外挂,通用,inner,print,return,写法,装饰,def From: https://www.cnblogs.com/xuetushiyongqi/p/17471213.html
一、装饰器通用写法
def wrapper_out(params)
print(params)
def wrapper(func):
def inner(*args,**kwargs):
print('打开外挂') # 执行前操作
res = func(*args,**kwargs)
print('关闭外挂') # 执行后操作
return res
return inner
return wrapper
二、装饰器嵌套
def wrapper1(func):
def inner(*args,**kwargs):
print('wrapper1打开外挂') # 执行前操作 1
res = func(*args,**kwargs)
print('wrapper1关闭外挂') # 执行后操作 5
return res
return inner
def wrapper2(func):
def inner(*args,**kwargs):
print('wrapper2打开外挂') # 执行前操作 2
res = func(*args,**kwargs)
print('wrapper2关闭外挂') # 执行后操作 4
return res
return inner
@wrapper1 # target = wrapper1(wrapper2.inner)
@wrapper2 # target = wrapper2(target) ---> wrapper2.inner
def target():
print('target') 3
执行顺序: 1,2,3,4,5
'''
def wrapper(game):
def inner():
print('打开外挂')
game()
print(wrapper.__name__)
print('关闭外挂')
return inner
@wrapper
def play_dnf():
print('德玛西亚!!!')
play_dnf()