Pyparsing has built-in quoted string support.
from pyparsing import OneOrMore,Word,alphanums,quotedString
item = Word('-',alphanums) | quotedString | Word(alphanums)
items = OneOrMore(item)
print items.parseString( "-a -b -c '1 2 3' -d 5 -e zork2000" )
gives:
['-a', '-b', '-c', "'1 2 3'", '-d'
Sergey wrote:
> Which module to use to do such thing:
>
> "-a -b -c '1 2 3'" -> ["-a", "-b", "-c", "'1 2 3'"]
>
> (i have string, need to pass it to getopt)
seems like CSV except that the seperator is space. You may check to see
if the CSV module can take space as delimiter.
--
http://mail.pytho
Sergey wrote:
> Which module to use to do such thing:
> "-a -b -c '1 2 3'" -> ["-a", "-b", "-c", "'1 2 3'"]
>>> import shlex
>>> shlex.split("-a -b -c '1 2 3'")
['-a', '-b', '-c', '1 2 3']
--
Giovanni Bajo
--
http://mail.python.org/mailman/listinfo/python-list