search

Home  >  Q&A  >  body text

python - 一个简单的装饰器例子报错

练习《PYTHON核心编程(第二版)》中一个有关函数装饰器的例子(例11.2),可是报类型错误,Type Error:'NoneType' object is not callable。一直查不出原因,请高手指点一下。所用Python是3.5.2版本。
程序代码如下:

错误提示:

天蓬老师天蓬老师2781 days ago679

reply all(2)I'll reply

  • PHP中文网

    PHP中文网2017-04-18 10:21:09

    Paste the source code text and then reply.

    reply
    0
  • 伊谢尔伦

    伊谢尔伦2017-04-18 10:21:09

    I have found the mistake. When defining the decorator function tsfunc, the return value should be the wrapped function object, not the wrapped function call. Should be written as "return wrappedFunc", not "return wrappedFunc()"

    reply
    0
  • Cancelreply