Another solution, possibly safer:

>>> from cStringIO import StringIO
>>> import csv
>>> s = "[16, 16, 2, 16, 2, 16, 8, 16]"
>>> sf = StringIO(s.strip()[1:-1])
>>> list(csv.reader(sf))
[['16', ' 16', ' 2', ' 16', ' 2', ' 16', ' 8', ' 16']]

Bye,
bearophile
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to