0

Say I have a list of similar functions:

def func1(a)
    foo(a=a)

def func2(b)
    foo(b=b)
...

the only difference of them is the argument name of foo, is that a short way to define them as one function, such as passing a argument name to the functions?

2
  • 3
    What's foo? It seems odd that you would have functions defined like this. Commented Apr 8, 2014 at 2:17
  • Why not just foo(a)? Commented Apr 8, 2014 at 2:19

1 Answer 1

3

You can do it by unpacking a keyword argument dictionary:

def combined(name, value):
    foo(**{name:value})

Then combined('a', a) is equivalent to func1(a). Whether this is a good idea is a separate consideration.

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.