Is there a simple way to parse this string ?
James Newton
jnewton at fuelindustries.com
Wed Dec 19 16:38:09 EST 2007
>I need to translate the following string
> a = '(0, 0, 0, 255), (192, 192, 192, 255), True, 8'
>
>into the following list or tuple
> b = [(0, 0, 0, 255), (192, 192, 192, 255), True, 8 ]
>Is there a simple way to to this.
>Stef Mientki
>>> a = '(0, 0, 0, 255), (192, 192, 192, 255), True, 8'
>>> b = eval(a)
>>> b
((0, 0, 0, 255), (192, 192, 192, 255), True, 8)
>>> c = list(eval(a))
>>> c
[(0, 0, 0, 255), (192, 192, 192, 255), True, 8]
More information about the Python-list
mailing list