[Python-Dev] Enumeration items: mixed types?

Ethan Furman ethan at stoneleaf.us
Tue Apr 30 01:16:48 CEST 2013


On 04/29/2013 03:50 PM, Ethan Furman wrote:
> This just doesn't make sense to me:
>
> --> class Stuff(Enum):
> ...     blue = 1
> ...     china = 'really big country'
> ...     random = (8273.199, 517)
>
> --> Stuff.blue.name == 'blue'
> --> Stuff.blue.value == 1
>
> --> Stuff.china.name == 'china'
> --> Stuff.china.value == ???
>
> --> Stuff.random.name == 'random'
> --> Stuff.china.value == ???
>
> In order to make this work at all, we have to support auto-numbering, and I didn't think we were going to do that in the
> class syntax?

I suppose the other option is to have `.value` be whatever was assigned (1, 'really big country', and (8273.199, 517) ), 
and the fact that `int(Stuff.china) ` blows up and doesn't store easily in a database is the programmers issue...

--
~Ethan~


More information about the Python-Dev mailing list