Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Same function with 2 different names and pass an arg setting

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".

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Output for func1:

hello
False

Output for func2:

hello
True

>Solution :

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)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading