Python 装饰器

例子如下

程序:

def log0(func):
    def wrapper(*a,**b):
        print('call log0 %s()' % func.__name__)
        return func(*a,**b)
    return wrapper

@log0
def func_b():
    print("func_b")

func_b()

输出:

call log0 func_b()
func_b

Process finished with exit code 0

a、b、wrapper、func换成什么都行

实现的功能就是在func_b的功能基础上,加上wrapper函数里的功能

原文地址:https://www.cnblogs.com/mghhzAnne/p/8963603.html