[Tutor] What would be good use cases for the enum module?

Mats Wichmann mats at wichmann.us
Sun Apr 9 08:58:02 EDT 2017


On 04/09/2017 01:54 AM, Alan Gauld via Tutor wrote:
> On 09/04/17 04:00, boB Stepp wrote:
> 
>> understandable to me, but I am having difficulty imagining where I
>> might want to use these features.
>>
> 
> Steven has given the basics, here are a few more real world examples:
> 
> Any kind of status value:
> (open,closed,opening, closing,locked)  - control valve
> (on, off) - light
> (red,green,amber,red-amber) - uk traffic light
> 
> small collections:
> days of week
> months in year
> (cleaning, reception, waiting, valet) - rota duties
> (hourly,daily,weekly,monthly,annual) - schedules

All of these can of course be done without enums.  So the extra benefit
of an enum is that the set is closed (immutable) and requires
uniqueness: picking some other value will be an error, adding a new
enumerator with an already used value is an error.

Not sure if the question really way "what good are enums" or "what good
is the new Python enum module"... in looking that over there seems to be
a lot of stuff, almost seems unlike the Python project to add something
with so many options, that really doesn't have *huge* utility.




More information about the Tutor mailing list