How to use argsparse to accept no flag and flag arguments

Question:

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

Asked By: Random Dude

||

Answers:

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

parser.add_argument('--verify', action='store_true')
Answered By: Msvstl
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.