You define an enumeration the same way as collections.namedtuple: with a type name, followed by a sequence of identifiers (it may be a string separated by commas and/or whitespace):

>>> STATE = enum('STATE', 'GET_QUIZ, GET_VERSE, TEACH')

It returns a (single) instance of a newly created type. The enumeration elements are integers, starting at 0, exposed as attributes. There is no way to change that: if you need specific values, look elsewhere. In fact, it is as if the enum were declared as:

# not actual code class STATE(object): __slots__ = () GET_QUIZ, GET_VERSE, TEACH = range(3) STATE = STATE()

The enumeration elements are read-only:

>>> STATE.GET_VERSE 1 >>> STATE.GET_VERSE = 8 Traceback (most recent call last): ... AttributeError: 'STATE' object attribute 'GET_VERSE' is read-only >>> del STATE.GET_VERSE Traceback (most recent call last): ... AttributeError: 'STATE' object attribute 'GET_VERSE' is read-only

This recipe has been tested with Python 2.4 ranging up to 3.1