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 we've …

  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 type, once you mix …

  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 values will be …

  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 are what …

  7. python - Getting value of enum on string conversion - Stack Overflow

    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 as a …

  8. 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 the value is …

  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 the enum …

  10. python - Is it possible to define a class constant inside an Enum ...

    Python 3.4 introduces a new module enum, which adds an enumerated type to the language. The documentation for enum.Enum provides an example to demonstrate how it can be extended: …