Parsing tuple from string?

Daniel the.doag at gmail.com
Thu Apr 24 00:21:26 EDT 2008


On Apr 23, 4:22 pm, George Sakkis <george.sak... at gmail.com> wrote:
> On Apr 23, 6:24 pm, Daniel <the.d... at gmail.com> wrote:
>
> > I have a list of strings, which I need to convert into tuples.  If the
> > string is not in python tuple format (i.e. "('one', 'two')", "("one",
> > 'two')", etc.), then I can just make it a 1-tuple (i.e. return
> > (string,) ).  If it is in python tuple format, I need to parse it and
> > return the appropriate tuple (it's ok to keep all tuple elements as
> > strings).
>
> > I think eval() will work for this, but I don't know what will be in
> > the string, so I don't feel comfortable using that.
>
> Check out one of the safe restricted eval recipes, e.g.http://preview.tinyurl.com/6h7ous.
>
Thank you very much!
> HTH,
> George




More information about the Python-list mailing list