代码语言:javascript复制
import time
from functools import wraps
def timethis(func):
'''
Decorator that reports the execution time.
'''
@wraps(func)
def wrapper(*args, *kwargs):
start = time.time()
result = func(args, **kwargs)
end = time.time()
print(func.name, end-start)
return result
return wrapper
解除装饰器
代码语言:javascript复制 @somedecorator
def add(x, y):
... return x y
...
orig_add = add.wrapped
orig_add(3, 4)
7