python enums with attributes
Question: Consider:

    
    
    class Item:
       def __init__(self, a, b):
           self.a = a
           self.b = b
    
    class Items:
        GREEN = Item('a', 'b')
        BLUE = Item('c', 'd')
    

Is there a way to adapt the ideas for simple enums to this case? (see [this
question](http://stackoverflow.com/questions/36932/whats-the-best-way-to-
implement-an-enum-in-python)) Ideally, as in Java, I would like to cram it all
into one class.

Java model:

    
    
    enum EnumWithAttrs {
        GREEN("a", "b"),
        BLUE("c", "d");
    
        EnumWithAttrs(String a, String b) {
          this.a = a;
          this.b = b;
        }
    
        private String a;
        private String b;
    
        /* accessors and other java noise */
    }
    


Answer: Use a
[namedtuple](http://docs.python.org/library/collections.html#collections.namedtuple):

    
    
    from collections import namedtuple
    
    Item = namedtuple('abitem', ['a', 'b'])
    
    class Items:
        GREEN = Item('a', 'b')
        BLUE = Item('c', 'd')
    

