Stringified list back to list of ints

bearophileHUGS at lycos.com bearophileHUGS at lycos.com
Wed Dec 12 14:46:42 EST 2007


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



More information about the Python-list mailing list