您的位置:首页 > 编程语言 > Python开发

python基础入门(六)

2018-03-18 16:01 543 查看

装饰器

# 作用:方便添加功能,不用更改API
import time
def timmer(func): #func=test
def wrapper():
# print(func)
start_time=time.time()
func() #就是在运行test()
stop_time = time.time()
print('运行时间是%s' %(stop_time-start_time))
return wrapper

@timmer # 相当于test=timmer(test)
def test():
time.sleep(3)
print('test函数运行完毕')
test()
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: