Skip to main content

Python StrEnum lets you access enum values without .value

This has always seemed unfortunately long and boilerplatey:

class PickOne(Enum):
    OPTION_A = "a"
    OPTION_B = "b"
 
choice = PickOne.OPTION_A # todo: show what would print at this point
print(PickOne.OPTION_A.value) # "a"

TIL that Python 3.11 introduced StrEnum and IntEnum, which let you access the underlying value without that extra .value:

print(PickOne.OPTION_A) # "a"

It’s the little things.