[Tutor] Python Version of "enum" ?

Alan Gauld alan.gauld at freenet.co.uk
Fri Oct 22 01:34:39 CEST 2004

> Is there an equivalent of C++'s 'enum' keyword to set a number of
> constants ( like so )
> enum {
> OFF,
> ON,
> };

Not as such but dictionaries can do much the same thing...

> If not, can you declare named constants another way? Perhaps 'const
> 1', for example.

I think that I read somewhere that there is a const construct
coming in Python soon? Don't think its in 2.4 yet but maybe 2.5?
But you can fake consts with classes if you need to.

Personally I take the consenting adults approach and just use
uppercase variable names to signify that "you change this one
at your peril..."

Alan G.

More information about the Tutor mailing list