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

推荐阅读更多精彩内容