How do I split a string with Python's shlex while preserving the quote characters that shlex splits on?
Two Words
"A Multi-line
comment."
['Two', 'Words', '"A Multi-line\ncomment."']
Note the double quotes wrapping the multi-line string. I read through the shlex documentation, but I don't see an obvious option. Does this require a regular expression solution?
>>> print(s)
Two Words
"A Multi-line
comment."
>>> shlex.split(s)
['Two', 'Words', 'A Multi-line\n comment.']
>>> shlex.split(s, posix=False)
['Two', 'Words', '"A Multi-line\n comment."']
>>>
Changed in version 2.6: Added the posix parameter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With