December 2021
Beginner
840 pages
47h 29m
English
Recall that we demonstrated (in Section 6.10.2) how to create a first-class counter closure in Python that encapsulates code and state and, therefore, resembles an object. Here we demonstrate how to use the object-oriented facilities in Python to develop a counter object. In both cases, we are binding an object (here, a function or method) to a specific context (or environment). In Python nomenclature, the closure approach is sometimes called nested scopes. However, in both approaches the end result is the same—a callable object (here, a function) that remembers its context.
While the ...