Book Review: Mastering Object-Oriented Python

Packt Publishing asked me to be a technical reviewer for one of their latest Python books, Mastering Object-Oriented Python by Steven Lott. This book is a sequel of sorts to their 2010 release, Python 3 Object Oriented Programming by Dusty Phillips, which I reviewed here.

Note: This book is explicitly for Python 3 developers and does NOT talk about Python 2 much at all.


Quick Review

  • Why I picked it up: I was asked by the publisher to be a part of editing the book, however this is just the sort of book I like to read
  • Why I finished it: It’s quite well written and you learn a lot about how the internals of classes work
  • I’d give it to: An intermediate Python programmer who wants to learn new things


Book Formats

You can get this book in paperback, epub, mobi, or PDF.


Book Contents

The book is split up into 3 parts or 18 chapters.


Full Review

This is one of Packt’s best books and also one of the best advanced Python books I’ve read. Let’s take a few moments to talk about the chapters. The book is based around the concept of casino Blackjack, which is kind of an odd topic for a programming book. Regardless, the author uses it and a few other examples to help demonstrate some fairly advanced topics in Python. The first chapter is all about Python __init__() method. It shows the reader how to use __init__ in a superclass and a factory function. The second chapter jumps into all of Python’s basic special methods, such as __repr__, __format__, __hash__, etc. You will learn a lot about metaprogramming in these first couple of chapters.

Chapter 3 digs into attributes, properties and descriptors. You will learn how to use __slots__, create immutable objects and work with “eagerly computer attributes”. Chapters 4-6 are about creating and working with callables, contexts and containers. There is information about memoization, creating custom callables, how to use __enter__ / __exit__, working with the collections module (deque, ChainMap, OrderedDict, etc) and more! Chapter 7 talks about creating your own Number, which was something I’d never considered doing. The author admits that you normally wouldn’t do it either, but he does teach the reader some interesting concepts (numeric hashes and in-place operators). Chapter 8 finishes up Part 1 with information on decorators and mixins.

Part 2 is all about persistence and serialization. Chapter 9 focuses on JSON, YAML and Pickle. The author favors YAML, so you’ll see a lot of examples using it in this section. Chapter 10 digs into using Python shelve objects and using CRUD operations in relation to complex objects. Chapter 11 is about SQLite. Chapter 12 goes into details of using Python to create a REST server and create WSGI applications. Chapter 13 rounds out Part 2 by covering configuration files using Python, JSON, YAML and PLIST.

The last section of the book covers testing, debugging, deploying and maintaining. It jumps right in with chapter 14’s topics on the logging and warning modules. Chapter 15 details how to create unittests and doctests in Python. Chapter 16 covers working with command line options via argparse and creating a main() function. In chapter 17, we learn how to design modules and packages. The last chapter of the book goes over quality assurance and documentation. You will learn a bit about the RST markup language and Sphinx for creating documentation.

I found Part 1 to be the most interesting part of the book. I learned a great deal about how classes work, metaprogramming techniques and the difference between callables and functions. I think the book is worth purchasing just for that section! Part 2 has a lot of interesting items too, although I question the author’s insistence on using YAML over JSON. I also do not understand why PLIST was even covered as a configuration file type. Part 3 seemed a bit rushed to me. The chapters aren’t as detailed nor the examples as interesting. On the other hand, I may be a bit jaded as this section was mostly material that I already knew. Overall, I found this to be one of the best Python books I’ve read in the last few years. I would definitely recommend it to anyone who wants to learn more about Python’s internals, especially Python’s “magic methods”.

masteringPythonOOP

Mastering Object-Oriented Python

by Steven F. Lott

Amazon

Packt Publishing


Other Book Reviews

5 thoughts on “Book Review: Mastering Object-Oriented Python”

  1. Since you say it’s a “sequel of sorts” to “Python 3 OOP”, I presume that like the other, this is oriented at v3? If so, does it clearly (and correctly) delineate what can and can’t be done in v2?

  2. very interested by the answer. Is this book about python3?
    Great review overall, I’m pretty sure to buy it soon 🙂

  3. Yes, this is a Python 3 book, although the concepts can be applied to Python 2 in most cases. I know the author discussed a couple of Python 3 only modules. The author makes it pretty clear that this book if just for people doing new application development in Python 3. I do not recall him talking about Python 2 much at all.

  4. Pingback: eBook Contest: Win a Free Copy of Mastering Object-oriented Python | Hello Linux

  5. Pingback: Book Review: Modern Python Cookbook - The Mouse Vs. The Python

Comments are closed.