Search code examples
pythoncommand-line-arguments

How to use argsparse to accept no flag and flag arguments


I want to do something like this

Case1: script.py --a="a_val" --b="b_val"
Both values are required for case 1

Case2: script.py --verify Just need the --verify without any value


Solution

  • Refer: https://docs.python.org/3/library/argparse.html

    parser.add_argument('--verify', action='store_true')