Enum questions.

Marko Rauhamaa marko at pacujo.net
Wed Apr 13 10:07:46 EDT 2016


Grant Edwards <grant.b.edwards at gmail.com>:
> On 2016年04月13日, Michael Selik <michael.selik at gmail.com> wrote:
>> An Enum corresponds to "nominal" data that is coded as a number
>> simply for storage rather than meaning.
>> FWIW, as an old Pascal programmer, I too would have been surprised
> that an "enum" is not ordinal and doesn't support a next/prev and
> iteration.
>> As an old C programmer, not so much. :)

>From the Pascal point of view, the "number for storage" seems odd. Why
not:
 class Color(enum.Enum):
 red = "red"
 blue = "blue"
 green = "green"
or:
 class Color(enum.Enum):
 red = object()
 blue = object()
 green = object()
or:
 class Color(enum.Enum):
 red
 blue
 green
This last one is to the point but raises a NameError.
Personally, I have not found enum.Enum all that appealing. If I have
needed such enums in my code, I have usually just defined:
 class MyClass:
 RED = "RED"
 BLUE = "BLUE"
 GREEN = "GREEN"
 
Marko


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /