-1

How can I pass *args from one function directly into another one called within it and maintain its functionality?

If I do it like this:

def parent(*args):
    child(args)

def child(*args):
    print(args)

I get this output:

>>> parent(1, 2, 3, 4)
>>> ((1, 2, 3, 4),)

but:

>>> child(1, 2, 3, 4)
>>> (1, 2, 3, 4)

I want the parent function to print out the same as if I called the child function directly.

Thanks!

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
SKings0
  • 23
  • 3

1 Answers1

4

Just unpack them before you give it to the next function.

def parent(*args):
    child(*args)

def child(*args):
    print(args)
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
pask
  • 899
  • 9
  • 19