[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library (original) (raw)

Ethan Furman ethan at stoneleaf.us
Fri Apr 26 00:23:55 CEST 2013


On 04/25/2013 03:07 PM, Barry Warsaw wrote:

On Apr 25, 2013, at 02:30 PM, Ethan Furman wrote:

--> class Animal(Enum): ... ant = 1 ... bee = 2 ... fly = 3

--> Animal(2) # should return Animal.bee --> Animal('ant') # should return Animal.ant It seems to me that storing the instances on the class as attributes is mostly for convenience; we could just as easily not, and change the repr of enumerators to ' ant [int=1]'. So I guess you would still expect these to hold true: >>> Animal.ant is Animal(2) True >>> Animal.ant is Animal('ant') True

Well, except for ant being 1, yeah. ;)

-- Ethan



More information about the Python-Dev mailing list