python常用的装饰器

#1.为函数添加统计时间的装饰器:
import time
def timeer(func):
    def inner():
        starttime=time.time()
        print(starttime)
        func()
        stoptime=time.time()
        print(stoptime)
        use_time=stoptime-starttime
        print(use_time)
    return inner

@timeer
def test():
    time.sleep(10)
    print("test")

test()

#2.为函数添加认证的装饰器:
def auth(func):
    
    def inner()
        
        func()
    return inner

猜你喜欢

转载自www.cnblogs.com/fengjunhua/p/8874505.html
今日推荐