About 192,000 results
Open links in new tab
  1. How can I represent an 'Enum' in Python? - Stack Overflow

    Aug 31, 2008 · I'm mainly a C# developer, but I'm currently working on a project in Python. How can I represent the equivalent of an Enum in Python?

  2. Python, what's the Enum type good for? - Stack Overflow

    Jun 3, 2016 · 149 In Python 3.4, we got an Enum lib in the standard library: enum. We can get a backport for enum that works with Python 2.4 to 2.7 (and even 3.1 to 3.3), enum34 in pypi. But …

  3. String-based enum in Python - Stack Overflow

    Oct 29, 2019 · When subclassing Enum, mix-in types must appear before Enum itself in the sequence of bases, as in the IntEnum example above. While Enum can have members of any …

  4. How to get all values from python enum class? - Stack Overflow

    Apr 8, 2015 · I'm using Enum4 library to create an enum class as follows: class Color(Enum): RED = 1 BLUE = 2 I want to print [1, 2] as a list somewhere. How can I achieve this?

  5. python - How can I construct an enum.Enum from a dictionary of …

    Nov 15, 2017 · Color = Enum('Color', color_values) Tada! There's a provided API for that. You can also give it an iterable of name-value pairs, or an iterable of just names (in which case the …

  6. Python Enum, when and where to use? - Stack Overflow

    Python 3.4.0 introduced enum, I've read the doc but still don't know the usage of it. From my perspective, enum.Enum is an extended namedtuple type, which may not be true. So these …

  7. Convert string to Enum in Python - Stack Overflow

    Dec 31, 2016 · In Python 3.11 you could also use a StrEnum. Granted, you would have to replace the values with strings as well, since it keyes on the value, not name (using enum.auto() for …

  8. python - Getting value of enum on string conversion - Stack …

    The single-underscore attributes are internal to the generated enum class; better stick to the documented attribute (which happens to be a special descriptor so that you can still use value …

  9. python - How does one get an Enum's members into the global …

    Jan 24, 2015 · Python now has an Enum type (new in 3.4 with PEP 435, and alse backported), and while namespaces are a good thing, sometimes Enums are used more like constants, and …

  10. How do I test if int value exists in Python Enum without using try ...

    Apr 26, 2017 · Using the Python Enum class, is there a way to test if an Enum contains a specific int value without using try/catch? With the following class: from enum import Enum class …