# -*-coding:utf-8-*- # author:murongtiedan import time def deco(func): def wrapper(): startTime = time.time() func() endTime = time.time() msecs = (endTime - startTime)*1000 print ("->elapsed time:%f ms" % msecs) return wrapper @deco #这个装饰器相当于 myfunc =deco(myfunc) def myfunc(): print("start myfunc") time.sleep(0.6) print("end myfunc") # print("myfunc is:",myfunc.__name__) # myfunc =deco(myfunc) # print("myfunc is:",myfunc.__name__) # print(myfunc()) print(myfunc())
一个基于python简单的装饰器实例
最新推荐文章于 2022-07-01 11:28:39 发布