Assuming I have the following parser:
def parse():
p = ArgumentParser()
p.add_argument('-c', 'client', help='')
p.add_argument('-s', 'server', help='')
args = vars(p.parse_args())
return args
I have to call it with python my_script.py -s bla -c bla
. I would like to add a third option, that will combine both of them, allowing me to call python my_script.py -x bla
and to get {'s': 'bla, 'c': 'bla'}
from the function, just like I would have got from the first call.
How can I do that?
I can do the opposite, i.e. create 2 args that will have the same name:
In [14]: p.add_argument('--x', dest='z')
...: p.add_argument('--y', dest='z')
...: p.parse_args('--x 1 --y 2'.split())
Out[14]: Namespace(z='2')
but that doesn't really help me...
This is not a dup. I don't want to pass a list. I already have the 2 options, and I want them to stay. I just want to have a third option that combines them. Using a list would make me dup my input, like this python my_script.py --list_param bla bla
where I want python my_script.py --x bla