[Python-Dev] PEP 435 -- Adding an Enum type to the Python standard library
Barry Warsaw
barry at python.org
Fri Apr 26 00:07:19 CEST 2013
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 '<Animal> 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
-Barry
More information about the Python-Dev
mailing list