Python 3.x 我试图将一个不可变的整数参数从一个函数传递到其他定义的函数;我犯了什么错?

Python 3.x 我试图将一个不可变的整数参数从一个函数传递到其他定义的函数;我犯了什么错?,python-3.x,error-handling,parameter-passing,chaining,Python 3.x,Error Handling,Parameter Passing,Chaining,假设我有一系列函数调用 def func1( pick, arg1, arg2 ): if pick == 1: do stuff with arg1 and arg2 elif pick == 2: do other stuff with arg1 and arg2 return stuff that got done def func2( pick, arg1, arg2, arg3 ): if pick == 1:

假设我有一系列函数调用

def func1( pick, arg1, arg2 ):
    if pick == 1:
        do stuff with arg1 and arg2
    elif pick == 2:
        do other stuff with arg1 and arg2 
    return stuff that got done

def func2( pick, arg1, arg2, arg3 ):
    if pick == 1:
        do stuff with arg1 and arg2 and arg3 
    elif pick == 2:
        do other stuff with arg1 and arg2 and arg3
    return stuff that got done

def func3( pick, func2, arg3 ):
    if pick == 1:
        do stuff with funcs and arg3
    elif pick == 2:
        do other stuff with funcs and arg3
    return stuff that done
etc ..
我能够通过SCIPY
quad
(数值积分)将参数从一个函数传递到另一个函数,以确保参数不可变。我还能够通过SCIPY
minimize
(优化)将参数从一个函数传递到另一个函数,其中参数是可变的。我的问题是将不可变输入
pick
从一个函数传递到另一个函数。如果我将
print(pick)
作为上述简化示例中每个已定义函数的第一行,并且如果我将此函数链称为

callme = func3( 2 , func2(pick = pick, args) , [6, 0.5] )
然后我的代码最终会抛出一条错误消息

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
但首先它会做一些类似的事情:

1
2
1
2
2 # (from pick = 2 in func3)
[6   0.5]
这种情况是如何发生的/为什么发生的?是否可以在函数调用链中将输入从一个函数发送到另一个函数


编辑:我的猜测是将pick作为类的对象传递,或者使用kwargs,或者将pick作为由单个元素组成的可解包元组传递;但我不确定这是否正确,或者如何实施。理想情况下,有一些我不知道的操作像
callme=func3(pick.func2,func2[6,0.5])
一样简单。我尝试将
pick
声明为
global
,但这会导致一条关于参数为全局参数的错误消息。

我从每个函数中删除了
pick
作为输入,但将其作为变量保留在functino中。然后,我将以下代码放在函数链之前,以初始化
拾取

def selectdist(pick):
    ## 1 for original representation
    ## 2 for normal representation on semilog(x) axis
    ## 3 for normal representation on linearly-spaced ln(x) axis
    return int(pick)

pickdist = selectdist(3) # choose 1 2 or 3
在功能链之后,使用重新初始化的
拾取
运行功能链。因为它不再是从函数链的顶部向下传递的参数,所以bug的来源就消失了