Fix Python – Get enumeration name by value [duplicate]


Asked By – Jiloc

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

Now we will see solution for issue: Get enumeration name by value [duplicate]


>>> Example(1).name

also see the Python docs.

This question is answered By – Nils Werner

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0