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) -

javascript - angular ng-required radio button not toggling required off in firefox 33, OK in chrome -

xcode - Swift Playground - Files are not readable -