TypeError: 'NoneType' object is not callable

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 not callable)