意外的TypeError:“ NoneType”对象不可调用

时间:2018-09-12 00:51:03

标签: python-3.x

我正在从“ Fluent Python”运行程序,遇到意外错误:

registry = []

def register(func):
    print("running register(%s)" % func)
    registry.append(func)

@register
def f1():
    print("runnning f1()")

@register
def f2():
    print("running f2()")

def f3():
    print("running f3()")

def main():
    print("running main()")
    print("registry ->", registry)
    f1()
    f2()
    f3()

if __name__ == "__main__":
    main()

它在运行时报告了意外错误

In [15]: !python registration.py
running register(<function f1 at 0x1070d9a60>)
running register(<function f2 at 0x1070dc0d0>)
running main()
registry -> [<function f1 at 0x1070d9a60>, <function f2 at 0x1070dc0d0>]
Traceback (most recent call last):
  File "registration.py", line 26, in <module>
    main()
  File "registration.py", line 21, in main
    f1()
TypeError: 'NoneType' object is not callable

我仔细检查了提示行f1()的错误行,但实际上无法找出代码中的任何问题:

0 个答案:

没有答案