new enum idiom

Rainer Deyke root at rainerdeyke.com
Wed Jan 10 17:45:31 EST 2001


"Alex Martelli" <aleaxit at yahoo.com> wrote in message
news:93i57b01qms at news2.newsguy.com...
> "Robert Amesz" <rcameszREMOVETHIS at dds.removethistoo.nl> wrote in message
> news:90259DC4Arcamesz at 127.0.0.1...
>     [snip]
> > >That's one possibility.  Syntax such as "bar=32" (for names in the
> > >enumlist whose value is explicitly defined) being another
>     [snip]
> > 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.
>
> Fine, but can't be "*much* easier" -- it's just one .split away from
> the 'bar=32' proposal to ('bar','32'), after all:-).

The problem with 'bar=32' is that it cannot be interleaved with unnumbered
args:

>>> enum('foo', bar=32, 'fee')
SyntaxError: non-keyword arg after keyword arg

Even if it could, there would be no way to determine the order of the
arguments and therefore no way to find out that 'fee' should have a value of
33.


--
Rainer Deyke (root at rainerdeyke.com)
Shareware computer games           -           http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list