Tricks to do "enums"?

Will Ware wware at world.std.com
Mon May 8 04:29:30 CEST 2000


Courageous (jkraska1 at san.rr.com) wrote:

> VAL1=0
> VAL2=1
> VAL3=3

Try this:

(VAL1, VAL2, VAL3) = range(3)

The only part you need to update is, if you add VAL4, you need to
change "range(3)" to "range(4)". But here's a C enum thing that I
don't know how to do in Python.

enum {
  first_guy,  /* probably will be assigned to zero */
  second_guy,  /* probably will be assigned to one */
  third_guy_special_value = 314159,
  fourth_guy   /* probably will be assigned to 314160 */
};    /* in any event, uniqueness is guaranteed for all values */

I suppose you could do something like this:
(VAL1, VAL2, VAL3, VAL4) = range(4)
VAL3 = 314159
but there's no longer a guarantee of uniqueness, which is usually
the point of an enum.
-- 
 - - - - - - - - - - - - - - - - - - - - - - - -
Resistance is futile. Capacitance is efficacious.
Will Ware	email:    wware @ world.std.com



More information about the Python-list mailing list