Rather than NewBreakfast
-style enums, suppose that in a project you still have OldBreakfast
-style enums, leftovers from Python2 days.
from enum import Enum
class OldBreakfast:
HAM = 0x00
EGGS = 0x01
PANCAKES = 0x02
class NewBreakfast(Enum):
HAM = 0x00
EGGS = 0x01
PANCAKES = 0x02
def eat():
food1 = OldBreakfast.HAM
food2 = NewBreakfast.HAM
print(food1)
print(food2)
eat()
As we see from eat()
ing in the code above, one benefit of moving from "old" to "new" is that while single-stepping or, here, printing, one can see what one is eating, rather than have to go back to the code and reverse-map the codes.
Pleasantly, updating the enums to the new style involves a very limited manipulation. In particular, only the definition itself is necessary. Everything else will work by magic.
Is this last statement indeed accurate? Are there traps that one needs to watch out for?