Wednesday, 15 September 2010

python - Splitting a string like shell would -



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']

python string shell

No comments:

Post a Comment