title: python : argparse boolean arguments via command line
body: <p>I would like to pass in arguments to this <code>sampleCode.py</code> file. </p>
  
  <pre><code>import argparse
  parser = argparse.ArgumentParser()
  parser.add_argument('--num_epochs', '-n', default=2, type=int)
  parser.add_argument('--directory', default='/some/string/')
  parser.add_argument('--exclude_hydro', default=False, action='store_true')
  
  args = parser.parse_args()
  print(args.num_epochs)    # 2
  print(args.exclude_hydro) # False
  </code></pre>
  
  <p>The following commands work for int and string arguments, but not for boolean.</p>
  
  <pre><code>$python3 sampleCode.py -n3                      #args.num_epochs=3
  $python3 sampleCode.py --num_epochs 3           #args.num_epochs=3
  $python3 sampleCode.py --directory /new/string  #args.directory = /new/string
  $python3 sampleCode.py --exclude_hydro True     #error
  </code></pre>
  
  <p><strong>How can I pass in boolean arguments?</strong> I have tried <code>type=bool</code> as a parameter for <code>.add_argument()</code> but that doesn't work.</p>