Simon Righley
Simon Righley

Reputation: 4969

Use tuple-returning Python function in another function call

I'm trying to do something like this in my code:

def fu():
    return np.array([1,2,3]), np.array([4,5,6])

def bar(x,y,z):
    print np.size(x)
    print np.size(y)
    print np.size(z)

bar(np.array([7,8]), fu())

but I'm getting an error message saying bar() takes exactly 3 arguments (2 given). How can I solve this problem?

Upvotes: 3

Views: 228

Answers (2)

7stud
7stud

Reputation: 48599

import numpy as np

def fu():
   return np.array([1,2,3]), np.array([4,5,6])

def bar(x,y,z):
   print np.size(x)
   print np.size(y)
   print np.size(z)

bar(np.array([7,8]), *fu())

--output:--
2
3
3

Upvotes: 0

arshajii
arshajii

Reputation: 129507

Try this:

bar(np.array([7,8]), *fu())

(unpack the tuple returned by fu())

Upvotes: 5

Related Questions