
On 02/01/2013 04:53 PM, Greg Ewing wrote:
Joao S. O. Bueno wrote:
class MyEnum(Enum): RED, GREEN, BLUE
load_constants(MyEnum, globals() )
The "obvious" way to spell this would be
from MyEnum import *
but it would be challenging to make that work, I suspect. :-(
It's not too tough: 8<---- constants.py -------------------------------------------------- class Colors(object): BLACK = 0 RED = 1 GREEN = 2 BLUE = 3 __all__ = ('BLACK','RED','GREEN','BLUE') @classmethod def register(cls): import sys sys.modules['%s.%s' % (__name__, cls.__name__)] = cls() Colors.register() 8<---- constants.py -------------------------------------------------- --> from constants.Colors import * --> RED 1 --> BLUE 3 ~Ethan~