Skip to content

Instantly share code, notes, and snippets.

@nickelpro
Created November 13, 2012 19:18
Show Gist options
  • Save nickelpro/4067780 to your computer and use it in GitHub Desktop.
Save nickelpro/4067780 to your computer and use it in GitHub Desktop.
Do-It-Yourself Enumeration in Python
class enum(object):
def __init__(self, *names):
for number, name in enumerate(names):
setattr(self, name, number)
Example:
Month = enum(
"January",
"Febuary",
"March",
...
"December",
)
print Month.January
print Month.March
print Month.December
Output:
0
3
11
@nickelpro
Copy link
Author

Gratefully copied from SO, just added the asterisk to allow for argument lists
http://stackoverflow.com/questions/702834/whats-the-common-practice-for-enums-in-python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment