title: shlex: Escaping quotes in Python 3
body: <p>I want to split the ascii text</p>
  
  <pre><code>1 'K\^o, Suk\'e'
  </code></pre>
  
  <p>which is printed as the Python string</p>
  
  <pre><code>line = "1 'K\\^o, Suk\\'e'\n"
  </code></pre>
  
  <p>into </p>
  
  <pre><code>['1', 'K\\^o, Suk\\'e']
  </code></pre>
  
  <p><code>shlex.split(line)</code> doesn't work, giving a <code>ValueError("No closing quotation")</code>.</p>
  
  <p>I tried adding to <code>wordchars</code> as follows:</p>
  
  <pre><code>&gt;&gt;&gt; lexer = shlex.shlex(line)
  &gt;&gt;&gt; lexer.wordchars += "\\'"
  &gt;&gt;&gt; list(lexer)
  ['1', "'K\\", '^', 'o', ',', "Suk\\'e'"]
  </code></pre>
  
  <p>but again this is not my intention.</p>
  
  <p>Without the quote, everything works as expected:</p>
  
  <pre><code>&gt;&gt;&gt; line2= "1 'K\\^o, Suk\\e'\n"
  &gt;&gt;&gt; shlex.split(line2)
  ['1', 'K\\^o, Suk\\e']
  </code></pre>
  
  <p>How can this be fixed?</p>
  
  <p>Edit: The closest I've come is:</p>
  
  <pre><code>&gt;&gt;&gt; lexer = shlex.shlex(line)
  &gt;&gt;&gt; lexer.wordchars += "\\'"
  &gt;&gt;&gt; lexer.wordchars += " "
  &gt;&gt;&gt; lexer.wordchars += "\\^"
  &gt;&gt;&gt; lexer.wordchars += ","
  &gt;&gt;&gt; list(lexer)
  ['1', "'K\\^o,", "Suk\\'e'"]
  </code></pre>
  
  <p>which is still not right.</p>
  
  <p>Edit: The example string is somewhat misleading. It should also be able to split, say</p>
  
  <pre><code>&gt;&gt;&gt; l1 = "C12 H2 'Hello friend'"
  </code></pre>
  
  <p><code>shlex</code> gets <code>l1</code> no problem.   </p>