new enum idiom

Robert Amesz rcameszREMOVETHIS at dds.removethistoo.nl
Thu Jan 11 07:38:51 EST 2001


Alex Martelli wrote:

>"Robert Amesz" <rcameszREMOVETHIS at dds.removethistoo.nl> wrote in
>message news:90259DC4Arcamesz at 127.0.0.1...
>>
>> [Snip]
>>
>> It also would be much easier to parse the argument list in that
>> form. 
>
>Fine, but can't be "*much* easier" -- it's just one .split away from
>the 'bar=32' proposal to ('bar','32'), after all:-).

Oh, allright. let's just call it a *little* easier, then. I mainly like 
the lispy flavour. Also, as a small extra bonus, you can use 
expressions with the tuple-notation. That allows you to do things like:

   #global constants
   base1 = 100
   base2 = 200

   #Someplace else
   xx = enum(('foo',base1), 'foo2', 'foo3', ('bar',base2), 'etc')


Of course, you can always eval() the right hand part of 'foo=base1', 
but the other form catches any syntax errors in those expressions 
before the program actually runs.


Robert Amesz



More information about the Python-list mailing list