string to integer problem

Peter Otten __peter__ at web.de
Sun Feb 8 12:00:59 EST 2004


Lol McBride wrote:

> I'm currently having problems with data returned from a MySQL database in
> as much as the data returned is of the form '(1,10,23,33,35,48)' i.e. a
> list variable holding 6 integers returned as a string.
> I can't seem to get around how to return the data to it's original format
> i.e. the list with 6 integers - I have tried slicing the string and

>>> s = '(1,10,23,33,35,48)'
>>> [int(n) for n in s[1:-1].split(",")]
[1, 10, 23, 33, 35, 48]

Peter



More information about the Python-list mailing list