Introspection at the module level?

Skip Montanaro skip at pobox.com
Sun Mar 7 15:10:27 CET 2004


    Roy> I've got a module that defines a bunch of constants:
    Roy> OP_FOO = 1
    Roy> OP_BAR = 2
    Roy> OP_BAZ = 37

    Roy> and so on.  The values are all unique.  I want to build, at module
    Roy> import time, a reverse map of these constants, i.e. I want to end
    Roy> up with:

    Roy> {1: "OP_FOO", 2: "OP_BAR", 37: "OP_BAZ"}

Have a look at

    http://manatee.mojam.com/~skip/python/ConstantMap.py

Skip




More information about the Python-list mailing list