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/125537.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 library [Python-Dev] PEP 435 -- Adding an Enum type to the Python standard libraryBarry Warsaw barry at python.org
Thu Apr 25 21:30:19 CEST 2013
On Apr 25, 2013, at 11:42 AM, Antoine Pitrou wrote:

>The PEP should mention how to get an enum from its raw value:
>
>    >>> Colors[1]
>    <EnumValue: Colors.red [value=1]>
>
>or:
>
>    >>> Colors(1)
>    <EnumValue: Colors.red [value=1]>

No, this is a failed experiment.  It's deprecated in flufl.enum and shouldn't
make it into stdlib enum.  getitem syntax is TOOWTDI.

>It would perhaps be nice to have a .get() method that return None if the
>raw value is unknown:
>
>    >>> Colors(42)
>    ...
>    ValueError: 42
>    >>> Colors.get(42)
>    >>> 

class Methods(Enum):
    set = 1
    get = 2
    delete = 3

What is "Methods.get"?

Catching the ValueError ``Methods[5]`` would raise doesn't seem so bad.

-Barry
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