What this book covers
We'll cover three advanced Python topics in a series of chapters that dig into the details.
- Some Preliminaries, covers some preliminary topics, such as unittest, doctest, docstrings, and some special method names.
Part 1, Pythonic Classes via Special Methods: This part looks more deeply at object-oriented programming techniques and how we can more tightly integrate the class definitions of our applications with Python's built-in features. It consists of nine chapters, which are as follows:
- Chapter 1, The _init_() Method, provides us with a detailed description and implementation of the
_init_()
method. We will look at different forms of initialization for simple objects. From this, we can look into more complex objects that involve collections and containers. - Chapter 2, Integrating Seamlessly with Python – Basic Special Methods, will explain in detail as to how we can expand a simple class definition to add special methods. We'll need to take a look at the default behavior inherited from the object so that we can understand what overrides are needed and when they're actually needed.
- Chapter 3, Attribute Access, Properties, and Descriptors, shows us how the default processing works in some detail. We need to decide where and when to override the default behavior. We will also explore descriptors and gain a much deeper understanding on how Python's internals work.
- Chapter 4, The ABCs of Consistent Design, looks at the abstract base classes in the
collections.abc
module in general. We'll look at the general concepts behind the various containers and collections that we might want to revise or extend. Similarly, we'll look at the concepts behind the numbers that we might want to implement. - Chapter 5, Using Callables and Contexts, looks at several ways to create context managers using the tools in
contextlib
. We'll show you a number of variant designs for callable objects. This will show you why a stateful callable object is sometimes more useful than a simple function. We'll also take a look at how to use some of the existing Python context managers before we dive in and write our own context manager. - Chapter 6, Creating Containers and Collections, focuses on the basics of container classes. We'll review the variety of special methods that are involved in being a container and offering the various features that containers offer. We'll address extending built-in containers to add features. We'll also look at wrapping built-in containers and delegating methods through the wrapper to the underlying container.
- Chapter 7, Creating Numbers, covers these essential arithmetic operators:
+
,-
,*
,/
,//
,%
, and**
. We'll also take a look at these comparison operators:<
,>
,<=
,>=
,==
, and!=
. We'll finish by summarizing some of the design considerations that go into extending or creating new numbers. - Chapter 8, Decorators and Mixins – Cross-cutting Aspects, covers simple function decorators, function decorators with arguments, class decorators, and method decorators.
Part 2, Persistence and Serialization: A persistent object has been serialized to a storage medium. Perhaps it's transformed to JSON and written to the filesystem. An ORM layer can store the object in a database. This part will take a look at the alternatives to handle persistence. This section contains five chapters, which are as follows:
- Chapter 9, Serializing and Saving – JSON, YAML, Pickle, CSV, and XML, covers simple persistence using libraries focused on various data representations such as JSON, YAML, pickle, XML, and CSV.
- Chapter 10, Storing and Retrieving Objects via Shelve, explains basic database operations with Python modules, such as
shelve
(anddbm
). - Chapter 11, Storing and Retrieving Objects via SQLite, moves to the more complex world of SQL and the relational database. Because SQL features don't match object-oriented programming features well, we have an impedance mismatch problem. A common solution is to use ORM to allow us to persist a large domain of objects.
- Chapter 12, Transmitting and Sharing Objects, takes a look at the HTTP protocol, JSON, YAML, and XML representation to transmit an object.
- Chapter 13, Configuration Files and Persistence, covers various ways in which a Python application can work with a configuration file.
Part 3, Testing, Debugging, Deploying, and Maintaining: We'll show you how to gather data to support and debug high-performance programs. This will include information on creating the best possible documentation in order to reduce the confusion and complexity of the support. This section contains the final five chapters, which are as follows:
- Chapter 14, The Logging and Warning Modules, takes a look at using the
logging
andwarning
modules to create audit information, as well as debug. We'll take a significant step beyond using theprint()
function. - Chapter 15, Designing for Testability, covers designing for testability and how we use
unittest
anddoctest
. - Chapter 16, Coping with the Command Line, takes a look at using the
argparse
module to parse options and arguments. We'll take this a step further and use the command design pattern to create program components that can be combined and expanded without resorting to writing shell scripts. - Chapter 17, The Module and Package Design, covers module and package design. This is a higher-level set of considerations. We will take a look at related classes in a module and related modules in a package.
- Chapter 18, Quality and Documentation, covers how we can document our design to create trust that our software is correct and has been properly implemented.