enum 0.2: Enumerations in Python
bignose+hates-spam at benfinney.id.au
Sun Nov 20 10:44:00 CET 2005
I've uploaded enum 0.2 to the Cheeseshop.
The main change is that enumeration values now export their enumtype,
index, and key (the things that define each value) as attributes.
Thanks to Bengt for making a convincing case in favour of this.
So now it's easier to ask an enumeration value about itself:
>>> from enum import Enum
>>> Weekdays = Enum('sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat')
>>> print [str(v) for v in Weekdays]
['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat']
>>> today = Weekdays.tue
>>> print str(today)
>>> print repr(today)
EnumValue(<enum.Enum object at 0xb7d1ceec>, 2, 'tue')
>>> print today.enumtype
<enum.Enum object at 0xb7d1ceec>
>>> print today.index
>>> print today.key
\ "I spilled spot remover on my dog. Now he's gone." -- Steven |
`\ Wright |
More information about the Python-list