美文网首页
TypeError: 'NoneType' object is

TypeError: 'NoneType' object is

作者: Kairk996 | 来源:发表于2019-07-23 06:16 被阅读0次

Python在使用decorator时,报错TypeError: 'NoneType' object is not callable

#!/usr/bin/env python3
# -*- coding = utf-8 -*-
import time


def cal_time(func):
    def wrapper():
        t1 = time.time()
        func()
        t2 = time.time()
        print(t2-t1)
    return wrapper()


def is_prime(role):
    if role < 2:
        return False
    elif role == 2:
        return True
    else:
        for i in range(2, role):
            if role % i == 0:
                return False
        return True


@cal_time
def echo_prime():
    for i in range(2, 10000):
        if is_prime(i):
            print(i)


echo_prime()

在使用decorator后,调用函数去掉括号就不会报错了

相关文章

网友评论

      本文标题:TypeError: 'NoneType' object is

      本文链接:https://www.haomeiwen.com/subject/gsdnlctx.html