Automatically setting an enum member's value in Python
Python tip:
When the exact value of an enum member is not important, you can use
auto()
to auto-generate it:The value starts at 1 and then increases incrementally by 1.
https://docs.python.org/3/library/enum.html#using-automatic-values
An example👇
from enum import Enum, auto class Status(Enum): DRAFT = auto() IN_REVIEW = auto() PUBLISHED = auto() DELETED = auto() print(list(Status)) """ [<Status.DRAFT: 1>, <Status.IN_REVIEW: 2>, <Status.PUBLISHED: 3>, <Status.DELETED: 4>] """