tcl-style string parsing

skaller skaller at maxtal.com.au
Tue Oct 19 15:47:45 EDT 1999


Dev wrote:
> 
> 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?

	Sure. Use Tcl. What I mean is,
write a C interface which actually calls
TCL to do the work, interfaced to Python.

	An easier method is to simply
grab the conversion code from TCL and
modify it to work in Python.

	[I have already done this, but the code
was taken down because no one was interested]

-- 
John Skaller, mailto:skaller at maxtal.com.au
1/10 Toxteth Rd Glebe NSW 2037 Australia
homepage: http://www.maxtal.com.au/~skaller
downloads: http://www.triode.net.au/~skaller




More information about the Python-list mailing list