Last active
June 3, 2020 12:29
-
-
Save Integralist/7571b0da0ca3da25f1cd170b1030f4a0 to your computer and use it in GitHub Desktop.
[Python Enum Example] #python #python3 #enum
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
""" | |
the 'inherit from enum' class approach helps give structure to otherwise | |
much more verbose constants. | |
for example... | |
RenderMode.HUMAN_READABLE | |
RenderMode.STRUCTURED_JSON | |
vs | |
RENDER_MODE_HUMAN_READABLE | |
RENDER_MODE_STRUCTURED_JSON | |
""" | |
class RenderMode(Enum): | |
HUMAN_READABLE = 1 | |
STRUCTURED_JSON = 2 | |
render_mode = RenderMode.STRUCTURED_JSON if settings.get('PRINT_STRUCTURED_JSON') else RenderMode.HUMAN_READABLE | |
if render_mode == RenderMode.HUMAN_READABLE: | |
# print data in human readable format | |
else: | |
# print data for machine consumption |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment