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...
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...
Jump to PostThere is a good recipe here http://code.activestate.com/recipes/577024-yet-another-enum-for-python/
Jump to Postcan 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 …
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
Enum is kinda useless. Use a dictionary.
@ ultimatebuster
yeah.....i am going for a dictionary instead. thanx...
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.