def log(text): def real_decorator(func): @functools.wraps(func) def wrapper(*args, **kw): if isinstance(text,str): display=text else:display='' print('begin call',display) func() print('end call') return wrapper if isinstance(text,str): return real_decorator else: return real_decorator(text) @log('ext') def f(): print('call f()') @log def f1(): print('call f1()') f() f1()
output
begin call ext call f() end call begin call call f1() end call
不知道是不是标准写法。。。总之可以work。。。
Sign in to make a reply
拉轰的小希红柿
output
不知道是不是标准写法。。。总之可以work。。。