Tokenise line containing string literals
<p>Using <code>str.split</code> on <code>"print 'Hello, world!' times 3"</code> returns the list <code>["print", "'Hello,", "world!'", "times", "3"]</code>. However, I want the result <code>["print", "'Hello, world!'", "times", "3"]</code>. How can I do that?</p>

<p><a href="https://www.tutorialspoint.com/python/string_split.htm" rel="nofollow"><code>.split()</code></a> function splits the <code>str</code> based on the delimiter. The default delimiter is a <code>blank space</code>. It doesn't care about the <code>'</code> within your string. In case you want to treat words within <code>'</code> as a single word. You should be using <a href="https://docs.python.org/2/library/shlex.html#shlex.split" rel="nofollow">shlex</a> library or you may write <code>regex</code> expression. Surely, <code>split()</code> is not what you are looking for.</p>

python string parsing