new enum idiom

Robert Amesz rcameszREMOVETHIS at dds.removethistoo.nl
Wed Jan 10 08:10:49 EST 2001


Alex Martelli wrote:

>[Enums]
>
>With some extra syntax, such as equal-signs, or arrowlike squigglies
>pointing in either explicit direction, expectations would surely
>firm up.  E.g., if I read:
>
>    xx = enum('foo', 'bar', 32, '<-fee', 'fie', 45, '<-flip',
>    'flop') 
>
>I would guess the arrows are suggesting 32 is the value of 'fee' and
>45 the value of 'flip, while if I read:
>
>    xx = enum('foo', 'bar->', 32, 'fee', 'fie->', 45, 'flip',
>    'flop') 
>
>then the different arrows would suggest 32 as the value of 'bar' and
>45 as that of 'fie'.
>
> [Snip]
>
>That's one possibility.  Syntax such as "bar=32" (for names in the
>enumlist whose value is explicitly defined) being another
>alternative, still better than 'just the list' (and a split on that
>form is enough to make it into the name/value pair, so it would be
>easy enough to accept either).


Either way seems rather ugly to me. Why not use tuples to visually 
suggest the link between the value and the string? In this case that 
would make:

 xx = enum('foo', ('bar',32), 'fee', ('fie',45), 'flip', 'flop') 

It also would be much easier to parse the argument list in that form.


Robert Amesz



More information about the Python-list mailing list