Argparse handles both i believe
https://docs.python.org/3/library/argpar...efix-chars
Im not sure beyond that as i never use + prefix for options.
I would assume something like this
https://docs.python.org/3/library/argpar...efix-chars
Im not sure beyond that as i never use + prefix for options.
I would assume something like this
-f/--foo or -b/--bar or +f/++foo or +b/++bar
can all be used. f
and foo
are result back to foo key in dictionary. import argparse parser = argparse.ArgumentParser(prog='PROG', prefix_chars='-+') parser.add_argument('+f', '++foo') parser.add_argument('-f', '--foo') parser.add_argument('+b', '++bar') parser.add_argument('-b', '--bar') args = vars(parser.parse_args()) print(args)
Output:metulburr@ubuntu:~$ python3.6 test11.py --foo test
{'foo': 'test', 'bar': None}
metulburr@ubuntu:~$ python3.6 test11.py -f test
{'foo': 'test', 'bar': None}
metulburr@ubuntu:~$ python3.6 test11.py -b b
{'foo': None, 'bar': 'b'}
metulburr@ubuntu:~$ python3.6 test11.py --bar test
{'foo': None, 'bar': 'test'}
metulburr@ubuntu:~$ python3.6 test11.py --bar test ++foo tester
{'foo': 'tester', 'bar': 'test'}
metulburr@ubuntu:~$ python3.6 test11.py --bar test --foo tester
{'foo': 'tester', 'bar': 'test'}
Recommended Tutorials: