Changing keyword defaults of a function in Python

Viewed 43

Let's say I have a function like this:

def func_1(a, b=1, c=None):
     code here

Now I want to make another function that has the same internals but different keyword arguments.

def func_2(a, b=2, c='asdf'):
    code here

One option would be a closure like this:

 def make_func(b, c):
     def func(a, b=b, c=c):
         code here
     return func

 func_1 = make_func(1, None)
 func_2 = make_func(2, 'asdf')

Is there a more concise/Pythonic way to go about this?

1 Answers
Related