title: optional nargs variable in argparse
body: <p>How I can do conditional loop with argparse with variable nargs? So, basically, it should run with or without argument.
  I am trying:</p>
  
  <pre><code>parser = argparse.ArgumentParser(description="output parser")
  group = parser.add_mutually_exclusive_group()
  group.add_argument("--dos", help="get DOSCAR for plot",
                     nargs="?", metavar=("int"))
  args = parser.parse_args()
  
  if args.dos:    
      if len(args.dos) &gt; 1:
          chosen = int(args.dos[0])
          chdos = "at_dos"+args.dos[0]+".dat"
      else:
          chosen = None
  
      inpt = "DOSY"
      print(chosen)
      print(inpt)
  </code></pre>
  
  <p>Now, if I have variable, then its printing some value, wrong but some value:</p>
  
  <pre><code>$python3 vasp.py --dos 111
  111
  None   # IT SHOULDN'T BE NONE
  DOSY
  </code></pre>
  
  <p>but nothing without argument.</p>
  
  <p>I have also tried with the normal sys.argv, as:</p>
  
  <pre><code>def get_dos():
      if len(sys.argv) &gt; 2:
          chosen = int(sys.argv[2])
          chdos = "at_dos"+sys.argv[2]+".dat"
      else:
          chosen = None
      inpt = "DOSCAR"
      print(sys.argv)
  
      print(args.dos)
      print(chosen)
      print(inpt)
  </code></pre>
  
  <p>in this case, when option is present, its giving correct result:</p>
  
  <pre><code>python3 vasp.py --dos 12
  ['vasp.py', '--dos', '12']
  12
  12
  DOSCAR
  </code></pre>
  
  <p>but again, nothing without option:</p>
  
  <pre><code>$python3 vasp.py --dos
  </code></pre>
  
  <p>I have tried with hpaulj's suggestion. It gives:</p>
  
  <pre><code>$python3 tt.py --dos 12
  Namespace(dos='12')
  1
  DOSY
  </code></pre>
  
  <p>and without argument, its still not printing anything.</p>