June 2019
Beginner to intermediate
770 pages
19h 24m
English
The standard library has a number of decorators. Modules such as contextlib, functools, unittest, atexit, importlib, and reprlib contain decorators that are excellent examples of cross-cutting aspects of a software design.
One particular example, the functools library, offers the total_ordering decorator that defines comparison operators. It leverages __eq__() and either __lt__(), __le__(), __gt__(), or __ge__() to create a complete suite of comparisons.
First, we'll need this class to fully define a playing card as follows:
from enum import Enumclass Suit(Enum): Clubs = "♣" Diamonds = "♦" Hearts = "♥" Spades = "♠"
This class provides the enumerated values for ...
Read now
Unlock full access