Posted on 16th September 2024|41 views
Could someone please tell me how can I represent an Enum in Python?
Posted on 16th September 2024| views
Here is one of the way to represent an Enum in Python:
class Enum(set):
def __getattr__(self, name):
if name in self:
return name raise AttributeError
Usage:
Animals = Enum(["elephant", "dog", "rat"])
print(Animals.elephant)