Conditional command line arguments in Python using argparse
The argparse module offers a way to do this without implementing your own requiredness checks. The example below uses “subparsers” or “sub commands”. I’ve implemented a subparser for “dump” and one for “format”. import argparse parser = argparse.ArgumentParser() parser.add_argument(‘file’, help=’The file you want to act on.’) subparsers = parser.add_subparsers(dest=”subcommand”) subparsers.required = True # required since … Read more