2

Let's say I have some functions (with different numbers of arguments) like this:

def add(n1=None, n2=None):
    return n1+n2

And I need to call them through the other, like this: call_another(function_name, arguments)

call_another(add, n1=1, n2=1)

I thought something with **kwargs:

def call_another(f, **kwargs):
   # How to call f() sending the arguments? 
   return f(kwargs)  # Obviously, don't work

I can't see a way to send the named arguments in kwargs to target function.

1 Answer 1

2

You should use **kwargs instead of kwargs. Artificial example:

>>> def ff(**kwargs):
...     print(kwargs)
>>> def call_another(f, **kwargs):
...     f(**kwargs)
>>> call_another(ff, a=1, b=2)
{'a': 1, 'b': 2}
Sign up to request clarification or add additional context in comments.

1 Comment

Damn it, this was my fail! Thanks. :-)

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.