Python 2.5 (r25:51918, Sep 19 2006, 08:49:13)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = '[1,2,3,4,5]'
>>> eval (a, {}, {})
[1, 2, 3, 4, 5]
>>>
But note that 'eval' is generally not such a good idea unless you
can completely trust your input source.   Depending on where your data is
coming from, you may very well be better off parsing the string data and
creating the list programatically.


>>> [int(i) for i in a.strip('[]').split(',')]
[1, 2, 3, 4, 5]

-Jeff

On 12/11/07, katie smith <[EMAIL PROTECTED]> wrote:
>
> How on earth do I convert strings to lists. I have a string with a list it
> in it  and I'm trying to convert it into a list. Please help me.
>
> Ex."[16, 16, 2, 16, 2, 16, 8, 16]"-string
> to [16, 16, 2, 16, 2, 16, 8, 16] -list
>
> ------------------------------
> Looking for last minute shopping deals? Find them fast with Yahoo! 
> Search.<http://us.rd.yahoo.com/evt=51734/*http://tools.search.yahoo.com/newsearch/category.php?category=shopping>
>
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to