我想为某个函数参数设置容差,但不为其他参数设置容差。假设我有这样的功能:
def myFnc(input1,param0 = 0, param1 =1):
return "input1:%s [params %s, %s]" %(input1, param0, param1)
这些是预期的结果:
>>>> myFnc(0.1, param0= 0.1, param1 = 1)
'input1:0.1 [params 0.1, 1]'
>>>> myFnc(0.1, param0= 0.12, param1 = 1)
'input1:0.1 [params 0.12, 1]'
>>>> myFnc(0.12, param0= 0.1, param1 = 1)
'input1:0.1 [params 0.1, 1]' #the same as the first instruction
我尝试使用 tol 并忽略,但我没有得到我期望的结果:
>>>> from klepto import inf_cache
>>>> f=inf_cache(tol=0,ignore=("**"))(myFnc);
>>>> f(0.1, param0= 0.1, param1 = 1)
'input1:0.1 [params 0.1, 1]'
>>>> f(0.1, param0= 0.12, param1 = 1)
'input1:0.1 [params 0.1, 1]' #I wanted [params 0.12, 1]
>>>> f(0.12, param0= 0.1, param1 = 1)
'input1:0.1 [params 0.1, 1]'
我正在使用从 pip (klepto.__version__ 0.1.1) 安装的 klepto。我应该更改键盘映射吗?