How to convert a string into a list

Mark Phillips mark at phillipsmarketing.biz
Mon Oct 4 21:10:50 EDT 2010


I have the following string - "['1', '2']" that I need to convert into a
list of integers - [1,2]. The string can contain from 1 to many integers. Eg
"['1', '7', '4',......,'n']" (values are not sequential)

What would be the best way to do this? I don't want to use eval, as the
string is coming from an untrusted source.

Thanks!

Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20101004/0c21356d/attachment.html>


More information about the Python-list mailing list