split a string of space separated substrings - elegant solution?
Karthik Gurusamy
kar1107 at gmail.com
Wed Aug 1 19:10:05 EDT 2007
On Aug 1, 12:41 am, Helmut Jarausch <jarau... at igpm.rwth-aachen.de>
wrote:
> Many thanks to all of you!
> It's amazing how many elegant solutions there are in Python.
Here is yet another solution.
pexpect.split_command_line()
>From the documentation:
split_command_line(command_line)
This splits a command line into a list of arguments.
It splits arguments on spaces, but handles
embedded quotes, doublequotes, and escaped characters.
It's impossible to do this with a regular expression, so
I wrote a little state machine to parse the command line.
http://pexpect.sourceforge.net/pexpect.html
But I am surprised to see there is a standard module already doing
this (shlex)
Karthik
>
> --
> Helmut Jarausch
>
> Lehrstuhl fuer Numerische Mathematik
> RWTH - Aachen University
> D 52056 Aachen, Germany
More information about the Python-list
mailing list