Next: 4.7 Mapping for Unions Up: 4. OMG IDL to Previous: 4.5 Mapping for Constants

#
4.6 Mapping for Enumerations

An IDL enumeration is mapped into a number of Python objects in an equivalent scope. There is one Python object for each member of the enumeration, and a single Python object with the same name as the enumeration type itself. e.g. consider the following IDL:

    Module Example {
        enum color {red, green, blue};
    };

In Python the enumeration can be used as follows:

    >>> import Example
    >>> Example.red
    red
    >>> Example.blue
    blue
    >>> Example.green
    green
    >>> Example.red == Example.blue
    0
    >>> for c in Example.color:
    ...     print c
    ...
    red
    green
    blue
    >>>

Note that enumerations can be compared and printed out, but you can make no other assumptions about how they are implemented (i.e. they cannot be treated as Python integers, or used in arithmetic operations etc). One concession has been made to allow the int method to be applied to enumeration members. This is useful to allow them to be used to index sequences.