title: How to parse strings to look like sys.argv
body: <p>I would like to parse a string like this:</p>
  
  <pre><code>-o 1  --long "Some long string"  
  </code></pre>
  
  <p>into this:</p>
  
  <pre><code>["-o", "1", "--long", 'Some long string']
  </code></pre>
  
  <p>or similar.</p>
  
  <p>This is different than either getopt, or optparse, which <em>start</em> with sys.argv parsed input (like the output I have above).  Is there a standard way to do this?  Basically, this is "splitting" while keeping quoted strings together.  </p>
  
  <p>My best function so far:</p>
  
  <pre><code>import csv
  def split_quote(string,quotechar='"'):
      '''
  
      &gt;&gt;&gt; split_quote('--blah "Some argument" here')
      ['--blah', 'Some argument', 'here']
  
      &gt;&gt;&gt; split_quote("--blah 'Some argument' here", quotechar="'")
      ['--blah', 'Some argument', 'here']
      '''
      s = csv.StringIO(string)
      C = csv.reader(s, delimiter=" ",quotechar=quotechar)
      return list(C)[0]
  </code></pre>