python 的装饰器
举例说明
def logging(level):
def outwrapper(func):
def wrapper(*args, **kwargs):
print("[{0}]: enter {1}()".format(level, func.__name__))
return func(*args, **kwargs)
return wrapper
return outwrapper
@logging(level="INFO")
def hello(a, b, c):
print(a, b, c)
hello("hello,","good","morning")
-----------------------------
>>>[INFO]: enter hello()
>>>hello, good morning
相当于执行logging(level='INFO')(hello)(a,b,c).变成outwrapper(hello)(abc),变成wrapper(abc),完成.
参考
https://zhuanlan.zhihu.com/p/87353829



