You can achieve this with store_const:
parser = argparse.ArgumentParser() parser.add_argument('-a', action='store_const', const=True, default=False) parser.add_argument('-b', action='store_const', const=True, default=False) args = parser.parse_args()
You can then invoke this from the command line, either using -a -b or using -ab (or -a or -b ).
Edit: and if you want one of the flags to take an argument, you need to pass it as the last element of the chain. Therefore, if a takes an argument, you need to do -bcda something
source share