[Python-ideas] adopt an enum type for the standard library?

Aaron Brady castironpi at comcast.net
Thu Jan 24 07:11:09 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)

And yes, there's also:

	wheres= Enum( UP= 0, DOWN= 0, LEFT= 0, RIGHT= 0 )
	print UP, DOWN, LEFT, RIGHT
	print wheres.UP, wheres.DOWN, wheres.LEFT, wheres.RIGHT
2 0 3 1
2 0 3 1

and:

	wheres= Enum( 0, 'UP DOWN LEFT RIGHT'.split() )
	print UP, DOWN, LEFT, RIGHT
	print wheres.UP, wheres.DOWN, wheres.LEFT, wheres.RIGHT
0 1 2 3
0 1 2 3




More information about the Python-ideas mailing list