[Python-ideas] adopt an enum type for the standard library?
Aaron Brady
castironpi at comcast.net
Thu Jan 24 06:55:56 CET 2008
> > What I usually do in Python is this:
> >
> > ERROR, OK, ALSO_OK = range(-1, -1 + 3)
> >
> > Start and stop values, as well step sizes other than one, are easily
> > achieved. Skipping values is done like this:
> >
> > ERROR, OK, ALSO_OK, SOMEOTHER, LAST = range(-1, -1 + 3) + range(1000,
> 1000 + 2)
Crazy:
wheres= Enum()
wheres.UP
wheres.DOWN
wheres.LEFT
wheres.close()
print UP, DOWN, LEFT, RIGHT
0 1 2 3
Crazier:
wheres= Enum()
while wheres.open:
with wheres:
UP, DOWN, LEFT, RIGHT
print UP, DOWN, LEFT, RIGHT
0 1 2 3
More information about the Python-ideas
mailing list