I have two Python functions, each of which takes variable arguments in its function definitions. To give a simple example:
def func1(*args):
for arg in args:
print arg
def func2(*args):
return [2 * arg for arg in args]
I would like to compose them - as in func1(func2(3, 4, 5))- but I do not want argsto func1was ([6, 7, 8],), I want it to be (6, 7, 8)as if it was named func1(6, 7, 8), and not func1([6, 7, 8]).
Normally I would simply use func1(*func2(3, 4, 5))or have func1to check if there was a args[0]list. Unfortunately, I can’t use the first solution in this particular instance, and to apply the second one I will need to perform such a check in many places ( func1there are many functions in the role ).
Does anyone have any ideas how to do this? I suppose some kind of introspection might be used, but I could be wrong.
source
share