How to pass list of function and all its arguments to be executed in another function in python? -
i have list of functions , arguments this:
(func1, *arg1), (func2, *arg2),... i want pass them function execute them this:
for func, arg* in (list of funcs, args): func(arg*) how in python? have tried several doesn't unpacking , *arg @ same time.
you can use *-operator unpack arguments out of tuple.
for example, suppose format of items in invocation list (function,arg1,arg2,...). in other words, item[0] function, while item[1:] arguments should given function.
def f1(x1): print("f1 {0}".format(x1)) def f2(x1,x2): print("f2 {0} {1}".format(x1,x2)) data in ((f1,5),(f2,3,4)): data[0](*data[1:]) # output: # f1 5 # f2 3 4
Comments
Post a Comment