Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Created February 15, 2022 10:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vlad-bezden/3980bc836cbdbb5455a76a281355b63d to your computer and use it in GitHub Desktop.
Save vlad-bezden/3980bc836cbdbb5455a76a281355b63d to your computer and use it in GitHub Desktop.
Python Custom Enum. It inherits from str and Enum, so it will return value in the f-string instead of name
from enum import Enum
class Status(str, Enum):
STOPPED = "STOPPED"
RUNNING = "RUNNING"
COMPLETE = "COMPLETE"
status = Status.RUNNING
print(status)
print(str(status))
print(f"{status}")
# Output:
# Status.RUNNING
# Status.RUNNING
# RUNNING
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment