开发者

What is the solution to complex Python parameter passing requirement?

I am looking for a solution to the following complex parameter pass problem:

I want to pass function's list along with its parameters as a parameter in another function using Python. I know it is possible to pass function as a parameter, but is it possible to pass lists of function and its arguments in a python?

My sample code:

self.myObject = Column(self.orderedColumnDictionary, \ 
   fillingOutMethods = [[fi开发者_StackOverflow社区rstFillingOutMethod, parameter1], \
   [anotherFillOutMethod, parameter2, parameter3]])

In this code, I am initializing an object of a class Column. So here while creating an object, I want to pass various functions as parameter. And I am thinking to pass all the functions that is needed for this object as a lits. For example, here in this sample code, my functions are firstFillingOutMethod, where I pass parameter1 as a parameter and my another function is anotherFillOutMethod, where I want to pass parameter2 and parameter3 as arguments.

Therefore I am looking forward for any suggestion to perform this kind of task.

Thank you


Here is an example:

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]

the output is:

[4, 12]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜