Iterate python Enum in definition order Iterate python Enum in definition order python python

Iterate python Enum in definition order


I found the answer here: https://pypi.python.org/pypi/enum34/1.0.

For python <3.0, you need to specify an __order__ attribute:

>>> from enum import Enum>>> class Shake(Enum):...     __order__ = 'vanilla chocolate cookies mint'...     vanilla = 7...     chocolate = 4...     cookies = 9...     mint = 3...     >>> for s in Shake:...     print(s)...     Shake.vanillaShake.chocolateShake.cookiesShake.mint