3

I have two functions:

def foo(*args, **kwargs):
    pass

def foo2():
    return list(), dict()

I want to be able to pass the list and dict from foo2 as args and kwargs in foo, however when I use it like

foo(foo2())

or

foo(*foo2())

tuple returned by foo2 gets assigned to *args. How should I do it properly?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
Bob K.
  • 33
  • 3

1 Answers1

3

You'll have to unpack your foo2() arguments into two names first, you can't directly use the two return values as *args and **kwargs with existing syntax.

Use:

args, kwargs = foo2()
foo(*args, **kwargs)
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343