我用下面的脚本用于功能test
评估是否这些值的范围内:装修后如何返回值?
x=[-5,5]
def test(x):
return x
def check(min,max):
def decorator(func):
def wrapper(*args,**kargs):
y=func(*args,**kargs)
for index in range(len(y)):
if y[index]>max:
y[index]=max
elif y[index]<min:
y[index]=min
return func(*args,**kargs)
return wrapper
return decorator
在该试验中,最小值为-1,最大是1,所以我用check(-1,1)(test(x))
用于为了装饰test(x)
得到期望的输出值为[-1,1]
。然而,输出是:
<function __main__.check.<locals>.decorator.<locals>.wrapper>
这不是预期的[-1,1]
。