[Python-ideas] PEP for enum library type?

Steven D'Aprano steve at pearwood.info
Wed Feb 13 00:08:19 CET 2013


On 13/02/13 06:50, Barry Warsaw wrote:
> On Feb 12, 2013, at 04:05 PM, Joao S. O. Bueno wrote:
>
>> That is too much ' ' typing - I think it would be ok, to have it like that,
>> but a helper function that would work just like the namedtuple call: Color =
>> Enum("Color", "RED GREEN BLUE", int)
>
> How about:
>
>      >>>  from flufl.enum import make
>      >>>  make('Colors', 'RED GREEN BLUE'.split())
>      <Colors {RED: 1, GREEN: 2, BLUE: 3}>


That reminds me of namedtuple. I could live with something close to that.

Like namedtuple, it should do the split for you.



-- 
Steven



More information about the Python-ideas mailing list