Enum questions.
Rustom Mody
rustompmody at gmail.com
Wed Apr 13 06:34:12 EDT 2016
On Wednesday, April 13, 2016 at 3:43:41 PM UTC+5:30, Antoon Pardon 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?
Given the eg in the docs:
from enum import Enum
class Color(Enum):
red = 1
blue = 2
green = 3
>>> Color(Color.red.value+1)
<Color.blue: 2>
>>> for i in range(Color.red.value,Color.green.value+1):
... print (Color(i))
...
Color.red
Color.blue
Color.green
If you say that is clunky I wont argue :-)
More information about the Python-list
mailing list