方法的通用装饰器
# 通用装饰器
def decorator(func):
def wrapper(*args, **kwargs):
print('----装饰器---start----')
result = func(*args, **kwargs)
print('----装饰器---end----')
# 返回原功能函数的调用的结果
return result # 如果没有返回,则打印 None
return wrapper
@decorator
def work2(a): # ==> work2 = decorator(work2)
print('----work2---a:', a)
return 'work2方法'
@decorator
def work3(a, b):
print('----work3----a--b--', a, b)
return 'work3方法'
if __name__ == '__main__':
print(work2(11))
print(work3(a=111, b=222))