About 189,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. String-based enum in Python - Stack Overflow

    Oct 29, 2019 · Formatted string literals, str.format (), and format () will use the mixed-in type’s format () unless str () or format () is overridden in the subclass, in which case the overridden …

  3. 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?

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

    Jun 3, 2016 · 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 …

  5. 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 …

  6. 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 …

  7. 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 …

  8. 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 …

  9. Convert string to Enum in Python - Stack Overflow

    Dec 31, 2016 · I mean I would like to convert a debug string to an enum of such: python class BuildType(Enum): debug = 200 release = 400

  10. python: how to convert if statements to enum or make it pythonic

    Aug 30, 2014 · Using a dict is a reasonable way to make this Pythonic—but so is using an enum. While the enum module wasn't built-in to the stdlib until Python 3.4, you can install enum34, a …