[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.python

RE: Is there a simple way to parse this string ?

James Newton

12/19/2007 9:38:00 PM

>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]