复杂Python参数传递要求的解决方案是什么?

Roh*_*ada 2 python parameter-passing

我正在寻找以下复杂参数传递问题的解决方案:

我想使用Python将函数列表及其参数作为参数传递给另一个函数.我知道可以将函数作为参数传递,但是可以在python中传递函数列表及其参数吗?

我的示例代码:

self.myObject = Column(self.orderedColumnDictionary, \ 
   fillingOutMethods = [[firstFillingOutMethod, parameter1], \
   [anotherFillOutMethod, parameter2, parameter3]])
Run Code Online (Sandbox Code Playgroud)

在这段代码中,我正在初始化一个类Column的对象.所以在创建对象时,我希望将各种函数作为参数传递.我正在考虑将此对象所需的所有函数作为lits传递.例如,在这个示例代码中,我的函数是firstFillingOutMethod,其中我将parameter1作为参数传递,而另一个函数是anotherFillOutMethod,其中我想传递parameter2和parameter3作为参数.

因此,我期待任何有关执行此类任务的建议.

谢谢

HYR*_*YRY 5

这是一个例子:

def f1(a):
    return a*a

def f2(a,b):
    return a*b

flist = [[f1, 2], [f2, 3, 4]]

print [item[0](*item[1:]) for item in flist]
Run Code Online (Sandbox Code Playgroud)

输出是:

[4, 12]
Run Code Online (Sandbox Code Playgroud)