python简单修饰器的用法(1)

@deco

def func():

print("hello")

time.sleep(1)

print("world")


def deco(func): //注意有个嵌套的方法 可以再次调用func() 相当于java中的代理模式 可以在一段固定的代码前面和后面的进行代码的添加

def wrapper():

startTime = time.time()

func()

endTime = time.time()

msecs = (endTime - startTime)*1000

print("time is %d ms" %msecs)

return wrapper

猜你喜欢

转载自blog.csdn.net/ying62506799/article/details/80875698