Get enumeration name by value


Are there any standard methods to get Enumeration names by value?

An example:

class Example(enum.Enum):
    one = 1
    two = 2

ex_variable = 1

Given ex_variable, can I obtain the string contained in

Asked By: Jiloc



>>> Example(1).name

also see the Python docs.

Answered By: Nils Werner

To access the members of enums programatically:

>>> Example(ex_variable).name
Answered By: AKS
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.