On 04/25/2013 04:26 PM, Glenn Linderman wrote:
My question is, once an enumeration is defined, is there a way, short of
element-by-element assignment, to import the
individual enumeration instances into the current namespace, so that I can sayĆ "red"
instead of "Color.red" ? I
understand the benefits of avoiding name collisions when there are lots of
enumerations, and lots of opportunities for
name collections between, say, RGBColor and CYMKColor... but there are lots of
uses for enumerations where the
subsidiary namespace is just aggravating noise.
You mean something like:
--> class Color(Enum):
... RED = 1
... GREEN = 2
... BLUE = 3
--> Color.register() # puts Color in sys.modules
--> from Color import * # doesn't work in a function, though :(
--> BLUE
Color.BLUE
Yeah, that would be nice. ;) A bit dangerous, though -- what if another module does the same thing, but its Color is
different?
Better would be:
--> Color.export(globals()) # put the enumerators in globals
--> RED
Color.RED
--
~Ethan~
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com