Constants and Enums

Rainer Deyke root at rainerdeyke.com
Thu Jun 29 15:18:35 EDT 2000


C. Porter Bassett <porter at et.byu.edu> wrote in message
news:Pine.GHP.4.21.0006291234020.9839-100000 at don.et.byu.edu...
> I am sure that this topic has been beat to death, but I can't seem to find
> the answer to my question.  I am used to programming in C/C++, and using
> many enums and #define ed constants.  In the absense of these, I have
> resorted to using tons of global variables, which makes me
> uncomfortable.  I know that the general concensus is to use dictionaries
> for all this, but I can't figure out how a dictionary would be usefule to
> use in place of an enum.  I am trying to think in a more python way, but I
> need a little nudging to get my brain to go that way.

In C:

enum bob { fred = 1, otto = 2 };
int n = fred;

In Python:

bob = {'fred':1, 'otto':2}
n = bob['fred']

Alternately:

class bob:
  fred = 1
  otto = 2

n = bob.fred


--
Rainer Deyke (root at rainerdeyke.com)
Shareware action/role-playing games      -      http://rainerdeyke.com
"In ihren Reihen zu stehen heisst unter Feinden zu kaempfen" - Abigor





More information about the Python-list mailing list