其他分享
首页 > 其他分享> > 装饰器运行时报错:TypeError: ‘NoneType’ object is not callable问题解决方法

装饰器运行时报错:TypeError: ‘NoneType’ object is not callable问题解决方法

作者:互联网

源代码

import time

def timmer(func):
    def warpper(*args,**kwargs):
        start_time = time.time()
        func()
        stop_time = time.time()
        print("in the func run time is %s" %(stop_time-start_time))
    return warpper()



@timmer
def test1():
    time.sleep(3)
    print("in the test1")

test1()

# 解决方法:调用函数时去掉括号   即 test1

import time

def timmer(func):
    def warpper(*args,**kwargs):
        start_time = time.time()
        func()
        stop_time = time.time()
        print("in the func run time is %s" %(stop_time-start_time))
    return warpper()



@timmer
def test1():
    time.sleep(3)
    print("in the test1")

test1

 

标签:test1,TypeError,timmer,object,callable,start,func,time,def
来源: https://www.cnblogs.com/zhengqiangchen/p/10857992.html