Entering strings as user input but interpreting as Python input (sort of)
Gabriel Genellina
gagsl-py2 at yahoo.com.ar
Mon Sep 17 21:58:59 EDT 2007
En Mon, 17 Sep 2007 21:01:38 -0300, Chris Carlen
<crcarleRemoveThis at BOGUSsandia.gov> escribi�:
> I'm writing a Python program, a hex line editor, which takes in a line
> of input from the user such as:
>
> >>> cmd = raw_input('-').split()
> -e 01 02 "abc def" 03 04
> >>> cmd
> ['e', '01', '02', '"abc', 'def"', '03', '04']
>
> Trouble is, I don't want to split the quoted part where the space occurs.
For this, try using the shlex module
<http://docs.python.org/lib/module-shlex.html>
The cmd module may be useful too, so you can concentrate on your own
functions, not the framework: <http://docs.python.org/lib/module-cmd.html>
--
Gabriel Genellina
More information about the Python-list
mailing list