Python 装饰器的使用方法

134 阅读1分钟

Python 装饰器的使用方法

from functools import wraps
def a(d):
    # 接收函数b
    @wraps(d)
    def c():
        print("hello")
        # 使用函数b
        d()
    # 必须有返回值
    return c

@a
def b():
    print("001")

b()

image-20211221111629774