Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

I have a string which is like this:

this is "a test"

I'm trying to write something in Python to split it up by space while ignoring spaces within quotes. The result I'm looking for is:

['this','is','a test']

1 Answer

0 votes
by (106k points)

You want split, from the shlex module.

>>> import shlex 

>>> shlex.split('this is "a test"') 

['this', 'is', 'a test']

Related questions

0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
asked Oct 3, 2019 in Python by Sammy (47.6k points)
0 votes
1 answer
0 votes
1 answer

Browse Categories

...