Why is argparse not parsing my boolean flag correctly? : <p>I am trying to use the argparse module to make my Python program accept flexible command-line arguments. I want to pass a simple boolean flag, and  saying <code>True</code> or <code>False</code> to execute the appropriate branch in my code. </p>

<p>Consider the following. </p>

<pre><code>import argparse

parser = argparse.ArgumentParser(prog='test.py',formatter_class=argparse.ArgumentDefaultsHelpFormatter)
parser.add_argument('-boolflag', type=bool, default=True)
parser.add_argument('-intflag' , type=int, default=3)
args = parser.parse_args()

boolflag = args.boolflag
intflag  = args.intflag


print ("Bool Flag is ", boolflag)
print ("Int Flag is ",  intflag)
</code></pre>

<p>When I tried to execute it with <code>python scrap.py -boolflag False -intflag 314</code> I got the result</p>

<pre><code>Bool Flag is  True
Int Flag is  314
</code></pre>

<p>Why is this?!! The intflag seems to be parsed correctly, yet the boolean flag is invariably parsed as <code>True</code> even if I mention explicitly in the command-line arguments that I want it to be <code>False</code>. </p>

<p>Where am I going wrong? </p>
