Keep it simple, using old Python 2.x (see below for Python 3!):
class Enum(object): def __init__(self, tupleList): self.tupleList = tupleList def __getattr__(self, name): return self.tupleList.index(name) Then:
DIRECTION = Enum(('UP', 'DOWN', 'LEFT', 'RIGHT')) DIRECTION.DOWN 1 Keep it simple when using Python 3:
from enum import Enum class MyEnum(Enum): UP = 1 DOWN = 2 LEFT = 3 RIGHT = 4 Then:
MyEnum.DOWN