Last active
August 25, 2017 19:12
-
-
Save townie/50b3f635d32223a1f719d4f38421cded to your computer and use it in GitHub Desktop.
py2_3_enum.py
This file contains hidden or 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
# put in __init__.py | |
def enum(*vals, **enums): | |
""" | |
Enum without third party libs and compatible with py2 and py3 versions. | |
""" | |
enums.update(dict(zip(vals, vals))) | |
return type('Enum', (), enums) | |
THING_TYPE = enum( | |
THE_GOOD='Good', | |
THE_BAD='Bad', | |
THE_UGLY='u g l y. you ugly!', | |
) | |
print(THING_TYPE.THE_GOOD) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment