February 2009
Intermediate to advanced
68 pages
1h 51m
English
Just as we can create decorators for functions and methods, we can also create decorators for entire classes. Class decorators take a class object (the result of the class statement), and should return a class—normally a modified version of the class they decorate. In this subsection we will study two class decorators to see how they can be implemented.
In the book’s examples there is a SortedList.py module that defines the Sort-edList custom collection class. This class aggregates a plain list as the private attribute self.__list, and eight of the SortedList class’s methods simply pass on their work to the private attribute. For example, here are how the Sort-edList.clear() and SortedList.pop() methods ...
Read now
Unlock full access