Enum questions.

Michael Selik michael.selik at gmail.com
Wed Apr 13 08:08:42 EDT 2016


On Wed, Apr 13, 2016, 12:14 PM Antoon Pardon <antoon.pardon at rece.vub.ac.be>
wrote:

> I have been looking at the enum documentation and it
> seems enums are missing two features I rather find
> important.
>
> 1) Given an Enum value, someway to get the next/previous
>    one
>
> 2) Given two Enum values, iterate over the values between
>    them.
>
> Did I miss those in the documentation or are they really
> missing?
>

An Enum corresponds to "nominal" data that is coded as a number simply for
storage rather than meaning. If you want next/previous you are thinking of
"ordinal" data which is coded as numbers for the purpose of comparison (but
not arithmetic). Placing nominal data in order would be comparing apples
and oranges, so to speak.

However, IntEnum should give you the features you want.

https://docs.python.org/3/library/enum.html#intenum

>



More information about the Python-list mailing list