xxxxxxxxxx
# Python compare enum
import enum
from functools import total_ordering
@total_ordering
class Grade(enum.Enum):
A = 5
B = 4
C = 3
D = 2
F = 1
def __lt__(self, other):
if self.__class__ is other.__class__:
return self.value < other.value
return NotImplemented
Grade.A >= Grade.B # True
Grade.A >= 3 # TypeError: '>=' not supported between instances of 'Grade' and 'int'