What's the common practice for enums in Python?

Joan Venge picture Joan Venge · Mar 31, 2009 · Viewed 131.5k times · Source

Possible Duplicate:
How can I represent an 'enum' in Python?

What's the common practice for enums in Python? I.e. how are they replicated in Python?

public enum Materials
{
    Shaded,
    Shiny,
    Transparent,
    Matte
}

Answer

Van Gale picture Van Gale · Mar 31, 2009
class Materials:
    Shaded, Shiny, Transparent, Matte = range(4)

>>> print Materials.Matte
3