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
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)
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
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)