Created
August 15, 2013 17:10
-
-
Save sneeu/6242605 to your computer and use it in GitHub Desktop.
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
def enum(name, attrs): | |
""" | |
>>> Fruit = enum('Fruit', 'apple banana cranberry') | |
>>> Fruit.apple #doctest: +ELLIPSIS | |
<object object at 0x...> | |
>>> Fruit.apple == Fruit.banana | |
False | |
>>> Animal = enum('Animal', 'cat dog elephant') | |
>>> Animal.cat #doctest: +ELLIPSIS | |
<object object at 0x...> | |
>>> Animal.dog == Animal.elephant | |
False | |
>>> Animal.cat == Fruit.apple | |
False | |
""" | |
return type(name, (object, ), {a: object() for a in attrs.split(' ')}) | |
if __name__ == '__main__': | |
import doctest | |
doctest.testmod() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment