enum 0.2: Enumerations in Python
Ben Finney
bignose+hates-spam at benfinney.id.au
Sun Nov 20 04:44:00 EST 2005
Howdy all,
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)
tue
>>> print repr(today)
EnumValue(<enum.Enum object at 0xb7d1ceec>, 2, 'tue')
>>> print today.enumtype
<enum.Enum object at 0xb7d1ceec>
>>> print today.index
2
>>> print today.key
tue
--
\ "I spilled spot remover on my dog. Now he's gone." -- Steven |
`\ Wright |
_o__) |
Ben Finney
More information about the Python-list
mailing list