If I have this function:
def foo(arg_one, arg_two):
pass
I can wrap it like so:
def bar(arg_one, arg_two):
return foo(arg_one, arg_two)
foo = bar
Is it possible to do this without knowing foo's required arguments, and if so, how?
You can use the argument unpacking operators (or whatever they're called):
def bar(*args, **kwargs):
return foo(*args, **kwargs)
If you don't plan on passing any keyword arguments, you can remove **kwargs.
You can use *args and **kwargs:
def bar(*args, **kwargs):
return foo(*args, **kwargs)
args is a list of positional arguments.
kwargs is a dictionary of keyword arguments.
Note that calling those variables args and kwargs is just a naming convention. * and ** do all the magic for unpacking the arguments.
Also see:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With