matching a string to extract substrings for which some function returns true

Amit Khemka khemkaamit at gmail.com
Tue Nov 22 07:18:26 EST 2005


Well actually the problem is I have a list of tuples which i cast as
string and then
put in a html page as the value of a hidden variable. And when i get
the string again,
i want to cast it back as list of tuples:
ex:
input: "('foo', 1, 'foobar', (3, 0)), ('foo1', 2, 'foobar1', (3, 1)),
('foo2', 2, 'foobar2', (3, 2))"
output: [('foo', 1, 'foobar', (3, 0)), ('foo1', 2, 'foobar1', (3, 1)),
('foo2', 2, 'foobar2', (3, 2))]

I hope that explains it better...

cheers,


On 11/22/05, Steven D'Aprano <steve at removethiscyber.com.au> wrote:
> On Tue, 22 Nov 2005 16:57:41 +0530, Amit Khemka wrote:
>
> > Hello All,
> >
> > say you have some string: "['a', 'b', 1], foobar ['d', 4, ('a', 'e')]"
> > Now i want to extract all substrings for which
> > "isinstance(eval(substr), list)" is "True" .
>
> That's an awfully open-ended question. Is there some sort of structure to
> the string? What defines a substring? What should you get if you extract
> from this string?
>
> "[[[[[]]]]]"
>
> Is that one list or five?
>
>
> > now one way is to walk through the whole sample string and check the
> > condition,
>
> Yes. Where does the string come from? Can a hostile user pass bad strings
> to you and crash your code?
>
>
> --
> Steven.
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>


--
----
Endless the world's turn, endless the sun's spinning
Endless the quest;
I turn again, back to my own beginning,
And here, find rest.



More information about the Python-list mailing list