3

so I have some code like the following:

def _step_1(a, b, c):
    some codes
    return d, e, f

def _step_2(d, e, f, a, b):
    some codes
    return g

def _run_all(a, b, c):
    g = _step_2(_step_1(a, b, c), a, b)
    return g

And it is telling me that I am missing two arguments "a" and "b". Could someone tell me if I did anything wrong by trying to save some steps? Or there is no way to save steps? I know I can definitely write like this:

def _run_all(a, b, c):
    d, e, f = _step_1(a, b, c)
    g = _step_2(d, e, f, a, b)
    return g
2
  • You're only passing three arguments to _step_2(). Even though the result of _step_1(a,b,c) contains three elements, it is itself just a tuple. As @U9-Forward answered, if you're using Python 3, you can automatically unpack that result into its three separate values. Commented Mar 1, 2019 at 5:21
  • Thank you for your explanation! And yes, I am using Python 3, it worked. Commented Mar 1, 2019 at 5:46

1 Answer 1

5

If your version is python 3, use unpacking (*):

def _run_all(a, b, c):
  g = _step_2(*_step_1(a, b, c), a, b)
  return g
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.