PEP 354: Enumerations in Python
greg at cosc.canterbury.ac.nz
Wed Mar 1 10:28:17 CET 2006
Giovanni Bajo wrote:
> What's the repr of an enumeration value? OTOH, it should be something like
> "Weekdays.wed", so that eval(repr()) holds true. Also, it'd be very useful in
> debug dumps, tracebacks and whatnot.
That would be nice, but I don't think that's possible
with what the PEP proposes, because in
Weekdays = enum('mon', 'tue', etc...)
there's no way for the enum object to know that it's
meant to be called 'Weekdays'.
A constructor argument could be added for this, but
then you end up having to write the name twice,
making the construct far less elegant.
Maybe *this* is a good argument for making the enum
object a class?
Or maybe it's an argument for allowing decorators
to operate on things other than functions, so you
could write something like
Weekdays = ('mon', 'tue', etc...)
More information about the Python-list