【发布时间】:2015-12-27 09:20:41
【问题描述】:
谁能告诉我如何将参数传递给装饰器调用函数?
def doubleIt(Onefunc):
def doubleIn():
return Onefunc()*Onefunc()
return doubleIn
@doubleIt
def Onefunc():
return 5
print(Onefunc()) # it prints out 25.
但是,当我尝试将我的 Onefunc() 升级到:
@doubleIt
def Onefunc(x):
return x
我面临以下错误:
TypeError
Traceback (most recent call last)
<ipython-input-17-6e2b55c94c06> in <module>()
9
10
---> 11 print(Onefunc(5))
12
TypeError: doubleIn() takes 0 positional arguments but 1 was given
错误是不言自明的,但我不确定如何更新 doubleIn() 函数来处理它。
【问题讨论】: