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~
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4