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
Post a Comment