装饰器
在不改变原来函数的基础上,给函数添加新的功能
import time
装饰器
def get_data(func):
def get_hello(*args,**kwargs):
begin_time = time.time()#开始时间
data = func() #调用函数
stop_time = time.time()#结束时间
print(stop_time - begin_time)
return data
return get_hello
@get_data #调用装饰器
def hello():
time.sleep(3)
print(12345)
return 'ok'
print(hello())