how to convert string to list or tuple
Simon Brunning
simon.brunning at gmail.com
Thu May 26 08:12:38 EDT 2005
On 5/26/05, flyaflya <flyaflya at gmail.com> wrote:
> a = "(1,2,3)"
> I want convert a to tuple:(1,2,3),but tuple(a) return ('(', '1', ',',
> '2', ',', '3', ')') not (1,2,3)
Short answer - use eval().
Long answer - *don't* use eval unless you are in control of the source
of the string that you are evaluating.
--
Cheers,
Simon B,
simon at brunningonline.net,
http://www.brunningonline.net/simon/blog/
More information about the Python-list
mailing list