标签:复习 fun func 开关 wrap lse div shu app
带参装饰器?
作用:关闭装饰器
实例
# 带参数的装饰器:(相当于开关)为了给装饰器传参 # F=True#为True时就把装饰器给加上了 F=False#为False时就把装饰器给去掉了 def outer(flag): def wrapper(func): def inner(*args,**kwargs): if flag: print(‘before‘) ret=func(*args,**kwargs) print(‘after‘) else: ret = func(*args, **kwargs) return ret return inner return wrapper @outer(F)#@wrapper def hahaha(): print(‘hahaha‘) @outer(F) def shuangwaiwai(): print(‘shuangwaiwai‘) hahaha() shuangwaiwai()
标签:复习 fun func 开关 wrap lse div shu app
原文地址:https://www.cnblogs.com/benson321/p/10059946.html