Python装饰器错误?

标签 python python-2.7 python-decorators

我尝试使用以下代码创建装饰器。

def outer():
    def inner():
        print 'inner called'
        return inner

foo = outer()
foo()

但是报错

TypeError: 'NoneType' object is not callable

请解决我的问题。谢谢..

最佳答案

我相信这是您想要的代码:

def outer():
    def inner():
        print 'inner called'
    return inner

foo = outer()
foo()

您的return 缩进太远

关于Python装饰器错误?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17066177/

相关文章:

python - 模板表单未在 Django 中呈现

python - 没有 BS4 python 类的刮表

python - 如何在 Django 中正确设置多个项目的环境设置?

python - 在装饰函数完成后,如何让 Python 装饰器运行?

python - 在装饰器中扩展 Python 中的类

python - 使用随机运算符将两个数字相加

Python ElementTree findall 不起作用

regex - 当模式具有相似文本时,如何使用 RegEx 在 Python 中获取所有匹配项?

python - Pandas :数据文件中没有列名

python - 为什么我的想法在 python2 中不起作用?