Skip to content

Instantly share code, notes, and snippets.

@linw1995
Last active March 24, 2021 07:16
Show Gist options
  • Select an option

  • Save linw1995/43396ece64a43684bd1db21e8d3b4d72 to your computer and use it in GitHub Desktop.

Select an option

Save linw1995/43396ece64a43684bd1db21e8d3b4d72 to your computer and use it in GitHub Desktop.
Enum class for creating enum members with name and value being same.
import enum
class AutoValue(enum.Enum):
# is same with the example of docs.python.org
# https://docs.python.org/3/library/enum.html#using-automatic-values
def _generate_next_value_(name, start, count, last_values):
return name
Color = AutoValue("Color", "red blue green")
assert Color['red'] == Color.red
assert Color('red') == Color.red
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment