[Python-ideas] Enums
Chris Rebert
pyideas at rebertia.com
Thu Jul 28 20:44:23 CEST 2011
On Thu, Jul 28, 2011 at 10:12 AM, Barry Warsaw <barry at python.org> wrote:
<snip>
> A few other things I've done in my experimental branch:
>
> - Added an optional argument `iterable` to make_enum() so that you can use the
> convenience function to auto-assign integer values other than sequentially
> incrementing from 1. E.g.
>
> >>> def enumiter():
> ... start = 1
> ... while True:
> ... yield start
> ... start <<= 1
> >>> make_enum('Flags', 'a b c d e f g', enumiter())
> <Flags {a: 1, b: 2, c: 4, d: 8, e: 16, f: 32, g: 64}>
Very neat, albeit of questionable enum-ness.
> - Renamed attributes .enumclass -> .enum and .enumname -> .name (hey, if
> you're going to be backward incompatible...)
Excellent. That just leaves SomeEnum(...) vs.SomeEnum[...].
Cheers,
Chris
More information about the Python-ideas
mailing list