0

I have a function def findSpace(aBookcase): which returns return row,column and another function which takes def setName(self, row, column, name):.

Now, when I execute aBookcase.setName(findSpace(aBookcase), name) I get TypeError: setName() takes exactly 4 arguments (3 given).

How can I make it parse the result from findSpace() as two arguments to function setName(), without changing findSpace(), because I have other code already depend on it

1
  • Does setName in a Class? Commented Nov 22, 2016 at 0:46

1 Answer 1

1

findSpace returns a tuple. That is one object. aBookcase.setName expects three separate arguments, in addition to the instance itself. Unpack the result and then use the arguments:

r,c = findSpace(aBookcase)
aBookcase.setName(r, c, name)

In Python 3.5 or higher, you can simply use *:

aBookcase.setName(*findSpace(aBookcase), name)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.