Reputation: 1344
Is there a simple way in Python to convert a string to a list using whitespaces as separators, but ignoring the whitespace within quoted text? IE: each word is treated as a separate search term, but any quoted text is treated as one term.
Upvotes: 3
Views: 1147
Reputation: 1123410
Yes, by using the shlex.split()
function:
>>> import shlex
>>> shlex.split('Some whitespace "separated string"')
['Some', 'whitespace', 'separated string']
Upvotes: 11