How to split string by space and preserve quoted strings in Python

1 Answer

0 votes
import shlex

string = 'python "java" c "c++" "c#"'

lst = shlex.split(string, posix=False)

print(lst)



'''
run:

['python', '"java"', 'c', '"c++"', '"c#"']

'''

 



answered Aug 6, 2022 by avibootz
...