Trees | Indices | Help |
|
---|
|
This module is designed to be the equivalent of the enum type in other languages. An enumeration object is created at run time, and contains named members that are the enumeration elements.
The enumeration is also a tuple of all of the values in it. You can iterate through the values, perform 'in' tests, slicing, etc. It also includes functions to lookup specific values by name, or names by value.
You can specify your own element values, or use the create factory method to create default Elements. These elements are unique system wide, and are ordered based on the order of the elements in the enumeration. They also are _repr_'d by the name of the element, which is convenient for testing, debugging, and generation text output.
>>> # Using Element values >>> Colors = Enumeration.create('red', 'green', 'blue')
>>> # Using explicitly specified values >>>Borders = Enumeration.create(('SUNKEN', 1), >>> ('RAISED', 32), >>> ('FLAT', 2))
>>> x = Colors.red >>> y = Colors.blue
>>> assert x < y >>> assert x == Colors('red') >>> assert Borders.FLAT == 2: >>> assert 1 in Borders
Note: slightly modified by Sebastian Thiel to be more flexible and suitable as base class
Contact: garret at bgb dot cc
License: freeware
|
|||
Element Internal helper class used to represent an ordered abstract value. |
|||
Enumeration This class represents an enumeration. |
|
|||
|
|
|||
__package__ =
|
|
Factory method for Enumerations. Accepts of list of values that can either be strings or (name, value) tuple pairs. Strings will have an Element created for use as their value. If you provide elements, the member returned when you access the enumeration will be the element itself. Example: Enumeration.create('fred', 'bob', ('joe', 42)) Example: Enumeration.create('fred', cls = EnumerationSubClass ) Example: Enumeration.create(Element('fred', Marge), ...)
|
Trees | Indices | Help |
|
---|
Generated by Epydoc 3.0.1 on Tue Apr 19 18:00:11 2011 | http://epydoc.sourceforge.net |