title: Python argparse - option with options to dict
body: <p>I am trying to parse some options with argparse.  I have found some similar problems discussed and found what I thought was a similar issue with a sensible solution given by Owen in <a href="https://stackoverflow.com/questions/17537465/options-with-options-with-python-argparse">Options with Options with Python argparse?</a></p>
  
  <p>I want to be able to specify, for example:</p>
  
  <pre><code>script.py infile --line &lt;path to file1&gt; beglab='str1' endlab='str2' 
                   --line &lt;path to file2&gt;  
                   --line &lt;path to file3&gt; beglab='str3' 
                   outfile
  </code></pre>
  
  <p>--line  can be specified multiple times.  Initially I had no extra arguments for the line option and I was able to create a list of the files without a problem using:</p>
  
  <pre><code>parser.add_argument("--line", action='append')
  </code></pre>
  
  <p>Now I need to optionally add labels to go with the lines.  There can be 0, 1 or 2 labels associated with a given line as shown above.  This is why I felt the example in the link provided seemed appropriate, unfortunately when I try:</p>
  
  <pre><code>parser.add_argument("--line", action='append', nargs="+")
  </code></pre>
  
  <p>And run:</p>
  
  <pre><code>script.py infile --line somefile beglab='A' endlab='B' 
                   --line otherfile beglab='a' endlab='b' outfile
  </code></pre>
  
  <p>or </p>
  
  <pre><code>script.py infile --line somefile outfile
  </code></pre>
  
  <p>I get an error stating that there are too few arguments.  If I remove the --line options from the command so I have just the positional ones, it works, so I know I haven't missed anything required.  So I went and I read up on the nargs options.  If --line is specified, it must have at least the filename, therefore I think that <code>nargs='+'</code> is the appropriate option, it looks about right in the help <code>[--line LINE [LINE ...]]</code>, so I am really confused about where this error has come from.</p>
  
  <p>I am happy to consider alternative methods of dealing with this, I just liked the simplicity of providing the inputs like this and creating a dictionary with them.</p>