[prev in list] [next in list] [prev in thread] [next in thread]
List: python-list
Subject: Re: PEP 354: Enumerations in Python
From: greg <greg () cosc ! canterbury ! ac ! nz>
Date: 2006-03-01 9:28:17
Message-ID: 46l8jaFbnfgeU4 () individual ! net
[Download RAW message or body]
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
@enum
Weekdays = ('mon', 'tue', etc...)
--
Greg
--
http://mail.python.org/mailman/listinfo/python-list
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic