#author F
import time
def timer(func):
def deco(*args, **kwargs): #保证传递所有参数都能使用
start_time = time.time()
func(*args, **kwargs)
stop_time = time.time()
print("cost time is %s" %(stop_time - start_time))
return deco
@timer # test=timer(test)
def test(name, sex):
print("{}'s sex is {}".format(name, sex))
test(1, 2)
Python通用装饰器
最新推荐文章于 2023-06-23 22:46:16 发布