title: Python: Using getpass with argparse
body: <p>I've had a look around, but couldn't find anything.</p>
  
  <p>Basically I was wondering if it was possible to use <code>getpass.getpass()</code> with argparse.</p>
  
  <p>At the moment I have the following as a work around, I was just wondering if there was a better way:</p>
  
  <pre><code>import argparse
  import getpass
  
  parser = argparse.ArgumentParser(description="Some description")
  parser.add_argument('-p', metavar="password", default="foobarblah123", help="password for user (default to prompt user)")
  ...
  parsed_args = parser.parse_args()
  args = vars(parsed_args)
  user_pass = args['p']
  if user_pass == "foobarblah123":
    user_pass = getpass.getpass()
  </code></pre>
  
  <p>I'm pretty sure this is not the best way to handle this, however, there is a requirement to have a command line option for the password ... best practice or not.</p>
  
  <p>Thanks.</p>