next up previous contents
Next: Mapping for Enumerations Up: OMG IDL to Python Previous: Mapping for Strings   Contents

Mapping for Constants

An IDL constant is mapped to a Python variable with an equivalent name and scope. The Python variable is initialised with the value of the constant. Of course, Python does not have real `constants', and nothing actually stops you assigning to these variables, but doing so is obviously not recommended.

e.g. consider the following IDL:

#pragma prefix "dstc.edu.au"

//
// Constant example.
//
module Example {

    const long MAX_LENGTH = 999;
    const string NAME = "Martin Chilvers";

    interface Foo {
        const float PI = 3.14;
    };
};

The constants can be used in Python as follows:

>>> import Example
>>> Example.MAX_LENGTH
999
>>> Example.NAME
`Martin Chilvers'
>>> Example.Foo.PI
3.14
>>>