A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2013-April/125566.html below:

[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library

[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard libraryEthan Furman ethan at stoneleaf.us
Fri Apr 26 01:53:31 CEST 2013
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~
More information about the Python-Dev mailing list

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