博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
python装饰器(备忘)
阅读量:7001 次
发布时间:2019-06-27

本文共 499 字,大约阅读时间需要 1 分钟。

# 装饰器decorator

def deco1(fun):

def PRINT(*args,**kwargs):
print('------deco1------')
fun(*args,**kwargs)
print('-----deco1 end------')
return PRINT

def deco2(fun):

def PRINT(*args,**kwargs):
print('------deco2------')
fun(*args,**kwargs)
print('-----deco2 end------')
return PRINT

@deco2
@deco1 #从下往上装饰
def fun(STR):
print("fun({})".format(STR))
fun("略略略")

'''

------deco2------

------deco1------
fun(略略略)
-----deco1 end------
-----deco2 end------

'''

转载于:https://www.cnblogs.com/LMIx/p/9683021.html

你可能感兴趣的文章