0.重点提要,必备模板 Python中一个标准的装饰器代码: 1234567891011import functools# func表示被装饰的函数def decorator(func): @functools.wraps(func) def wrapper(*args, **kwargs): # before func is invoked, do somethings value = func(*args, *kwargs) # after func is invoked, do somethings return value return wrapper 装饰器必须返回一个函数,而不是函数调用 ref https://www.dusaiphoto.com/article/139/#_10 https://cloud.tencent.com/developer/article/1391579