Is there a simple way to parse this string ?

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Dec 19 19:56:41 EST 2007


En Wed, 19 Dec 2007 19:23:36 -0300, John Machin <sjmachin at lexicon.net>  
escribió:

> On Dec 20, 9:10 am, Larry Bates <larry.ba... at websafe.com> wrote:
>> Stef Mientki wrote:
>>
>> > 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.
>
> In particular Paul Maguire recently pointed to a safe evaluator that
> was restricted (IIRC) to something like lists/dicts/etc of ints/floats/
> string/etc constants -- looks like just what you need.

There is also a Cookbook recipe for a safe_eval function at  
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469

> Does anyone know of a newsreader that can automatically killfile
> people who suggest eval without any warnings at all? Or should we let
> Darwinian selection take its effect?

Doesn't work, Darwininan selection would act on the unfortunate people  
asking, not on who careless answers "use eval" :(

-- 
Gabriel Genellina




More information about the Python-list mailing list