python装饰器'NoneType' object is not callable解析

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

def simple_decorator(f):
    print('enter function')
    f()
    print('exited function')

@simple_decorator
def hello():
    print('hello world')

hello()

对于装饰器理解不够的话会写出类似与上面的代码,运行结尾就会出现'NoneType' object is not callable,把最后的:

hello()

改为

hello

就可以解决,具体解释参考:
http://www.tuicool.com/articles/FBZvya

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容