python time装饰器log 类似Java 中注解

'''
Created on 2019年11月2日

@author: Administrator
'''
import time

def timefun(func):
    def wrappedfunc():
        print("start the method : %s"%(func.__name__))
        start = time.time()
        rst = func()
        end = time.time()
        print("end the method : %s"%(func.__name__))
        print("total cost time :", str((end-start)))
        return rst
    return wrappedfunc

@timefun
def foo():
    time.sleep(1)
    print("I am foo")

@timefun
def getInfo():
    return '----hahah---'

f = foo()
print(type(f))
原文地址:https://www.cnblogs.com/lshan/p/11876872.html