next up previous contents
Next: 4.6 Mapping for Enumerations Up: 4. OMG IDL to Previous: 4.4 Mapping for Strings

4.5 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
>>>



http://www.fnorb.com/
March 2000