April 2014
Beginner to intermediate
634 pages
15h 22m
English
Integrating Seamlessly with Python – Basic Special Methods
Attribute Access, Properties, and Descriptors
Python exposes a great deal of its internal mechanisms through its special method names. The idea is pervasive throughout Python. A function such as len() will exploit the __len__() special method of a class.
What this means is that we have a tidy, universal public interface (len(x)) that works on any kind of class. Python's polymorphism is based in part on the way any class can implement a __len__() ...