0

can anyone suggest a simple method to define an enum in python.

as some examples floating on net, i used

class Animal:
DOG=1
CAT=2
print Animal.DOG


but it doesn't seem to be working...

5
Contributors
6
Replies
7
Views
6 Years
Discussion Span
Last Post by novice20
0

I got a solution on one of the forums...

class Materials:
Shaded, Shiny, Transparent, Matte = range(4)

>>> print Materials.Matte
3

If U have better ideas, do suggest pls....

0

can anyone suggest a simple method to define an enum in python.

as some examples floating on net, i used

class Animal:
DOG=1
CAT=2
print Animal.DOG


but it doesn't seem to be working...

This works ...

class Animal:
    DOG = 1
    CAT = 2

print Animal.DOG  # 1
0

@ ultimatebuster
yeah.....i am going for a dictionary instead. thanx...

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.