Skip to content

Instantly share code, notes, and snippets.

@bheklilr
Created April 27, 2015 15:58
Show Gist options
  • Save bheklilr/445c8bf956eb576dc941 to your computer and use it in GitHub Desktop.
Save bheklilr/445c8bf956eb576dc941 to your computer and use it in GitHub Desktop.
from collections import OrderedDict
class enummeta(type):
def __init__(cls, name, bases, classdict):
super(enummeta, cls).__init__(name, bases, classdict)
cls.__values__ = [v for v in classdict.values() if v not in (__name__, enummeta)]
def __iter__(cls):
return iter(cls.__values__)
class TestEnum(object):
__metaclass__ = enummeta
foo = 'foo'
bar = 'bar'
baz = 'baz'
qux = 'qux'
print list(TestEnum)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment