matching a string to extract substrings for which somefunctionreturns true
Fredrik Lundh
fredrik at pythonware.com
Tue Nov 22 16:15:02 EST 2005
I wrote:
> if you cannot cache session data on the server side, I'd
> recommend inventing a custom record format, and doing your
> own parsing. turning your data into e.g.
>
> "foo:1:foobar:3:0+foo1:2:foobar1:3:1+foo2:2:foobar2:3:2"
>
> is trivial, and the resulting string can be trivially parsed by a couple
> of string splits and int() calls.
on the other hand, the "myeval" function I posted here
http://article.gmane.org/gmane.comp.python.general/433160
should be able to deal with your data, as well as handle data from
malevolent sources without bringing down your computer.
just add
if token[1] == "(":
out = []
token = src.next()
while token[1] != ")":
out.append(_parse(src, token))
token = src.next()
if token[1] == ",":
token = src.next()
return tuple(out)
after the corresponding "[" part, and call it like:
data = myeval("[" + input + "]")
</F>
More information about the Python-list
mailing list