tcl-style string parsing

Dev devnull at fleetingimage.com
Tue Oct 19 14:50:05 EDT 1999


I have a string consisting of multiple strings---

  a = '"This, m\'dear,"  is  "an example" "of a parsing problem."'

I would like to efficiently convert this to a list (or tuple):

  b = ["This, m'dear,", "is", "an example", "of a parsing problem."]

In the source string, note that whitespace
within a quoted string should be retained,
whitespace outside a quoted string should be ignored,
and strings without whitespace don't need to be quoted.

I'm converting some code from TCL, where this is trivial.
(The original string can be treated and indexed as a list.)
I've not found a suitable re expression for this, nor a set
of string replacements.

Any ideas?

--Dev





More information about the Python-list mailing list