codescrape/enum.py
2015-09-08 21:56:08 -05:00

7 lines
301 B
Python

# Pythonic way to do enums:
# http://stackoverflow.com/a/1695250/195722
def enum(*sequential, **named):
enums = dict(zip(sequential, range(len(sequential))), **named)
reverse = dict((value, key) for key, value in enums.iteritems())
enums['val'] = reverse
return type('Enum', (), enums)