Created
February 15, 2022 10:27
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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