最佳答案
我有一个像下面这样的设计师。
def myDecorator(test_func):
return callSomeWrapper(test_func)
def callSomeWrapper(test_func):
return test_func
@myDecorator
def someFunc():
print 'hello'
我想提高这个装饰接受下面这样的另一个参数
def myDecorator(test_func,logIt):
if logIt:
print "Calling Function: " + test_func.__name__
return callSomeWrapper(test_func)
@myDecorator(False)
def someFunc():
print 'Hello'
但是这个代码给出了错误,
TypeError: myDecorator ()正好有2个参数(给定1个)
为什么函数没有自动传递? 如何显式地将函数传递给装饰函数?