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...

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....

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

Why that didnt worked? How come? :)

Enum is kinda useless. Use a dictionary.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.