为什么我在此处运行调用时遇到上述异常。我觉得我错过了一些非常明显的东西......
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()
答案 0 :(得分:2)
必须是return simple_decorator
而不是return decorator_factory
def decorator_factory(arg1, arg2):
def simple_decorator(f):
def wrapper():
print arg1
f()
print arg2
return wrapper
return simple_decorator # <--- HERE
@decorator_factory("what the heck", "what the heck2")
def hello():
print "Hello World"
hello()