【发布时间】:2017-03-12 17:55:08
【问题描述】:
为什么我在此处运行调用时会出现上述异常。我觉得我错过了一些非常明显的东西..
def decorator_factory(arg1, arg2):
def simple_decorator(f):
def wrapper():
print arg1
f()
print arg2
return wrapper
return decorator_factory
@decorator_factory("what the heck", "what the heck2")
def hello():
print "Hello World"
hello()
【问题讨论】:
-
请仔细检查您的缩进。除此之外,您所写的内容并没有明显的错误。请提供完整回溯的minimal reproducible example。
-
必须是
return simple_decorator而不是return decorator_factory -
对不起,让我在这里再次复制它。看起来在这里粘贴代码给了我你们在这里提到的问题。
标签: python python-2.7 python-decorators