keven ren keven ren - 8 months ago 13
Python Question

Input of a function contains output of another function

A bit of a general question that I cannot find the solution for,

I currently have two functions

def func1(*args, **kwargs):
return a,b


def func2(x,y):
return variables

I would like my code to evaluate

variables = func2(func1())

Which python does not accept as it says func2 requires two arguments when only one is given. My current solution is doing an intermediate dummy redefinition but makes my code extremely cluttered (my "func1" has an output of many parameters).

Is there an elegant solution to this?

def func1():
    return 10, 20

def func2(x, y):
    return x + y

results = func2(*func1())
print results


A function can only return one thing, so func1() actually returns the tuple (10, 20). In order to get two things, you need to explode the tuple with *.