On 1/30/2013 10:30 AM, Michael Foord wrote:
On 30 January 2013 15:22, Michael Foord
With a Python 3 metaclass that provides default values for *looked
up* entries you could have this:
class Color(Enum):
RED, WHITE, BLUE
The lookup would create the member - with the appropriate value.
class values(dict):
def __init__(self):
self.value = 0
def __getitem__(self, key):
So RED, WHITE, BLUE are 1, 2, 3; not 0, 1, 2 as I and many readers might expect. That aside (which can be fixed), this is very nice.