string to list? possible?

Jan Dries jan.dries at dcube-resource.be
Sun Jan 20 15:08:34 EST 2002


maximilianscherr wrote:

> i need to convert a string like "[1, 2, 3, 4]" to a list [1, 2, 3, 4].
> possible?


How about this:

Python 2.1 (#15, Apr 16 2001, 18:25:49) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
 >>> s = "[1,2,3,4]"
 >>> l = eval(s)
 >>> print type(l)
<type 'list'>
 >>> print l
[1, 2, 3, 4]
 >>>


Regards,
Jan





More information about the Python-list mailing list