Welcome, guest | Sign In | My Account | Store | Cart
def enum(names):
    "Create a simple enumeration having similarities to C."
    return type('enum', (), dict(map(reversed, enumerate(
        names.replace(',', ' ').split())), __slots__=()))()

Diff to Previous Revision

--- revision 8 2011-01-10 15:02:54
+++ revision 9 2013-01-31 14:16:06
@@ -1,8 +1,4 @@
 def enum(names):
-    names = names.replace(',', ' ').split()
-    space = dict(map(reversed, enumerate(names)), __slots__=())
-    return type('enum', (object,), space)()
-
-# Alternatively:
-
-enum = lambda names: type('enum', (object,), dict(map(reversed, enumerate(names.replace(',', ' ').split())), __slots__=()))()
+    "Create a simple enumeration having similarities to C."
+    return type('enum', (), dict(map(reversed, enumerate(
+        names.replace(',', ' ').split())), __slots__=()))()

History