[Python-ideas] constant/enum type in stdlib
Michael Foord
fuzzyman at gmail.com
Wed Jan 30 17:35:25 CET 2013
On 30 January 2013 16:26, Antoine Pitrou <solipsis at pitrou.net> wrote:
> Le Wed, 30 Jan 2013 15:22:06 +0000,
> Michael Foord <fuzzyman at gmail.com> a
> écrit :
> > On 30 January 2013 07:26, Antoine Pitrou
> > <solipsis at pitrou.net> wrote:
> >
> > > On Wed, 30 Jan 2013 17:58:37 +1300
> > > Greg Ewing <greg.ewing at canterbury.ac.nz>
> > > wrote:
> > > > Guido van Rossum wrote:
> > > >
> > > > > class color(enum):
> > > > > RED = value()
> > > > > WHITE = value()
> > > > > BLUE = value()
> > > >
> > > > We could do somewhat better than that:
> > > >
> > > > class Color(Enum):
> > > > RED, WHITE, BLUE = range(3)
> > >
> >
> >
> >
> > With a Python 3 metaclass that provides default values for *looked up*
> > entries you could have this:
> >
> > class Color(Enum):
> > RED, WHITE, BLUE
>
> This relies on tuple evaluation order,
It does if you do them as a tuple.
> and would also evaluate any
> other symbol looked up from inside the class body
Only if they aren't actually defined.
> (which means I
> cannot add anything else than enum symbols to the class).
>
>
So not true - it is only *undefined* symbols that are added as enum values.
> In other words, I'm afraid it would be somewhat fragile ;)
>
Well, within specific parameters...
Michael
>
> Regards
>
> Antoine.
>
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> http://mail.python.org/mailman/listinfo/python-ideas
>
--
http://www.voidspace.org.uk/
May you do good and not evil
May you find forgiveness for yourself and forgive others
May you share freely, never taking more than you give.
-- the sqlite blessing http://www.sqlite.org/different.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20130130/6a95c7f5/attachment.html>
More information about the Python-ideas
mailing list