2

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

and

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?

kevqnp
  • 153
  • 10
  • func1 returns 2 parameters, which I would like to use it as a input for funct2. The second argument is the second value that is output by func1 – kevqnp Apr 20 '16 at 06:21
  • Consider if nesting function calls like this is a good idea. They can be a pig to debug. – cdarke Apr 20 '16 at 06:58

1 Answers1

4
def func1():
    return 10, 20


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

results = func2(*func1())
print results

--output:--
30

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 *.

7stud
  • 46,922
  • 14
  • 101
  • 127