import time def log(delay=0): def decorator(func): def wrapper(*args, **kwargs): """我是 wrapper 的注释""" time1 = time.time() newargs = list(args) newargs[0] = newargs[0] * 2 # res = func(*args, **kwargs) res = func(*newargs, **kwargs) time.sleep(delay) # 延迟 delay 秒 time2 = time.time() print("函数名:{}".format(func.__name__)) print("函数注释内容:{}".format(func.__doc__)) print("入参 args :{}".format(args)) print("入参 kwargs :{}".format(kwargs)) print("返回值:{}".format(res)) print("函数执行耗时:{:.8f}".format(time2 - time1)) return res return wrapper return decorator @log(0) def get_prime_sum(n): """我是 get_prime_sum 的注释""" sum = 0 for i in range(1, n + 1): sum += i return sum get_prime_sum(50)
标签:args,format,python,sum,kwargs,time,print,拦截,装饰 From: https://www.cnblogs.com/wujf/p/17094679.html