Reuven M. Lerner @lernerpython.com · 8d

Enums are a great addition to #Python: from enum import Enum class Days(Enum): SUN = 1 MON = 2 TUE = 3 WED = 4 THU = 5 FRI = 6 SAT = 7 They print nicer and are symbolic! But... not sortable (yet).

1 likes 2 replies

?

Replies

Brian Hicks · 8d

I wondered if you can define comparison methods here and it turns out you can! This works fine. @functools.total_ordering class Day(Enum): SUN = 1 # … SAT = 7 def __lt__(self, other): return self.value < other.value

Simson Garfinkel · 8d

Should SUN be 0? Or should it be 6? Probably not 1?