python - Splitting a string like shell would -


i'm reading line file looks this

key1=4 key2="hello world" 

i split list

['key1=4', 'key2=hello world'] 

is there simple way shell-like processing in python without having walk string searching next ' ' or '"' , incrementally processing it?

use shlex.split:

>>> import shlex >>> s = 'key1=4 key2="hello world"' >>> shlex.split(s) ['key1=4', 'key2=hello world'] 

Comments

Popular posts from this blog

c++ - QTextObjectInterface with Qml TextEdit (QQuickTextEdit) -

xcode - Swift Playground - Files are not readable -

jboss7.x - JBoss AS 7.3 vs 7.4 and differences -