Welcome, guest | Sign In | My Account | Store | Cart

Notice! PyPM is being replaced with the ActiveState Platform, which enhances PyPM’s build and deploy capabilities. Create your free Platform account to download ActivePython or customize Python with the packages you require and get automatic updates.

Download
ActivePython
INSTALL>
pypm install enum

How to install enum

  1. Download and install ActivePython
  2. Open Command Prompt
  3. Type pypm install enum
 Python 2.7Python 3.2Python 3.3
Windows (32-bit)
0.4.4 Available View build log
Windows (64-bit)
0.4.4 Available View build log
Mac OS X (10.5+)
0.4.4 Available View build log
Linux (32-bit)
0.4.4 Available View build log
Linux (64-bit)
0.4.4 Available View build log
 
Author
License
Choice of GPL or Python license
Dependencies
Imports
Lastest release
version 0.4.4 on Jan 5th, 2011

This package provides a module for robust enumerations in Python.

An enumeration object is created with a sequence of string arguments to the Enum() constructor:

>>> from enum import Enum
>>> Colours = Enum('red', 'blue', 'green')
>>> Weekdays = Enum('mon', 'tue', 'wed', 'thu', 'fri', 'sat', 'sun')

The return value is an immutable sequence object with a value for each of the string arguments. Each value is also available as an attribute named from the corresponding string argument:

>>> pizza_night = Weekdays[4]
>>> shirt_colour = Colours.green

The values are constants that can be compared only with values from the same enumeration; comparison with other values will invoke Python's fallback comparisons:

>>> pizza_night == Weekdays.fri

System Message: ERROR/3 (<string>, line 22)

Inconsistent literal block quoting.

True >>> shirt_colour > Colours.red True >>> shirt_colour == "green" False

Each value from an enumeration exports its sequence index as an integer, and can be coerced to a simple string matching the original arguments used to create the enumeration:

>>> str(pizza_night)

System Message: ERROR/3 (<string>, line 33)

Inconsistent literal block quoting.

'fri' >>> shirt_colour.index 2

Subscribe to package updates

Last updated Jan 5th, 2011

Download Stats

Last month:4

What does the lock icon mean?

Builds marked with a lock icon are only available via PyPM to users with a current ActivePython Business Edition subscription.

Need custom builds or support?

ActivePython Enterprise Edition guarantees priority access to technical support, indemnification, expert consulting and quality-assured language builds.

Plan on re-distributing ActivePython?

Get re-distribution rights and eliminate legal risks with ActivePython OEM Edition.