Same function with 2 different names and pass an arg setting

Question:

Is it possible to have a single function that can be run with two different names and pass a new arg setting as well as all others?

I am thinking something like this:

def func1(a, b=False):
    print(a)
    print(b)

func2 = func1(b=True)

Where this function is being run by other code on the command line and a is a string, lets say I set it to "hello".

Output for func1:

hello
False

Output for func2:

hello
True
Asked By: alphadmon

||

Answers:

Just define another function that calls the first function after setting the b argument to True.

def func2(*args, **kwargs):
    kwargs['b'] = True
    func1(*args, **kwargs)
Answered By: Barmar
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.