Chapter 1. The Python Data Model
Guido’s sense of the aesthetics of language design is amazing. I’ve met many fine language designers who could build theoretically beautiful languages that no one would ever use, but Guido is one of those rare people who can build a language that is just slightly less theoretically beautiful but thereby is a joy to write programs in.
Jim Hugunin, creator of Jython, cocreator of AspectJ, and architect of the .Net DLR1
One of the best qualities of Python is its consistency. After working with Python for a while, you are able to start making informed, correct guesses about features that are new to you.
However, if you learned another object-oriented language before Python,
you may find it strange to use len(collection) instead of collection.len().
This apparent oddity is the tip of an iceberg that, when properly understood,
is the key to everything we call Pythonic.
The iceberg is called the Python Data Model,
and it is the API that we use to make our own objects play well with the most idiomatic language
features.
You can think of the data model as a description of Python as a framework. It formalizes the interfaces of the building blocks of the language itself, such as sequences, functions, iterators, coroutines, classes, context managers, and so on.
When using a framework, we spend a lot of time coding methods that are called by the framework. The same happens when we leverage the Python Data Model to build new classes. The Python interpreter ...