import functools
def time_d(*args, **kwargs):
print(f"1-time_d的装饰器参数 args: {args} kwargs: {kwargs}")
def decorate(func):
print(7)
@functools.wraps(func)
def wrapper(*args, **kwargs):
print(f"9-func_name-time_d: {func.__name__}")
result = func(*args, **kwargs)
print(13)
return result
print(8)
return wrapper
print(2)
return decorate
def time_c(*args, **kwargs):
print(f"3-time_c的装饰器参数 args: {args} kwargs: {kwargs}")
def decorate(func):
print(5)
@functools.wraps(func)
def wrapper(*args, **kwargs):
print(f"10-func_name-time_c: {func.__name__}")
result = func(*args, **kwargs)
print(12)
return result
print(6)
return wrapper
print(4)
return decorate
@time_d('120', name='arley')
@time_c('110', name='chen')
def func_name(name):
print(11)
return f"result: {name}"
result = func_name('chen')
print(result)
"""
1-time_d的装饰器参数 args: ('120',) kwargs: {'name': 'arley'}
2
3-time_c的装饰器参数 args: ('110',) kwargs: {'name': 'chen'}
4
5
6
7
8
9-func_name-time_d: func_name
10-func_name-time_c: func_name
11
12
13
result: chen
"""
|