Skip to content

Instantly share code, notes, and snippets.

@townie
Last active August 25, 2017 19:12
Show Gist options
  • Save townie/50b3f635d32223a1f719d4f38421cded to your computer and use it in GitHub Desktop.
Save townie/50b3f635d32223a1f719d4f38421cded to your computer and use it in GitHub Desktop.
py2_3_enum.py
# 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