Author: Michael Driscoll
Audience: Python programmers ready to go second level
Reviewer: Sue Gee
What can you expect from a book on "Intermediate Python"?
This book, based on Python 3, is the sequel to the first book by Michael Driscoll, Python 101 (see my review) and so there is no beginner's material and it's assumed you've already covered all that.
Its thirty chapters are split into five parts as follows:
Part I - Intermediate Modules
Part II - Odds and Ends
Part III - Web
Part IV - Testing
Part V - Concurrency
Like Python 101 the book cover is worthy of comment with a very amusing deign by Varya Kolesnikova. Why are there mice in the classroom? I reckon it's to do with the title Mouse Vs Python of Mike Driscoll's blog.
The book is highly practical and presents the concepts mainly, and sometimes exclusively, it covers through code, Accordingly the very first chapter dives straight into a whirlwind tour of the argparse module. There's a brief preamble:
Have you ever wondered how to process command line arguments in Python? Yeah there's a module for that. .. I have always found that the simplest way to explain a coding concept is to show some code. So that's what we are going to do. Here's a super simple example that doesn't do much of anything.
before we get to code.
The next intermediate module to be covered is the collections module with the following being explored in code:
After this we get to Context Managers and learn to create our own in order to see how they works. Function overloading and caching come next in a chapter on the functools module.
Chapters 5 and 6 are devoted to imports and the import module; 7 and 8 to iterators and generators with the itertools module; 9 constitutes an introduction to regex (regular expressions) in Python while using the re module and 10 looks at the typing module which adds type hinting to Python.
Part II has eight chapters that look at topics that need to covered but don't really fit neatly into any specific section: Python built ins (map filter and more); unicode; benchmarking; encryption and cryptography; connecting to databases; the super function; descriptors and scope (local, global and nonlocal).
The final thee parts each have four chapters on defined topics. Part III on working with the Web is rather more discursive than previous sections of the book. Its initial chapter is on Web Scraping and has general tips before looking at the use of BeautifulSoup, one of the most popular HTML parsers, and the Scrapy framework for crawling website and extracting data. Then in a chapter Web APIs we look at how to extract data from Twitter, Reddit and Wikipedia. How to connect to an FTP server to download and upload files using Python's ftplib and how to work with URLs using Python's urllib are each given a chapter.
Part IV goes back to being code-led. Its initial chapter looks at doctest, a very useful built-in module that checks that any docstrings used for examples execute properly and thus helps when writing documentation. The next two chapters cover the unittest module and its mock submodule and the there's an introduction to the third party coverage.py tool used for measuring code coverage.
Four modules that allow you to write concurrent code so that your programs can do more than one task at the same time are covered in Part V, and as usual there a lot of code with much of it being by way of really simple examples to allow you to understand what is going on.
First comes the asyncio module which introduced the keywords async and await into Python 3.5. Then comes an introduction to threads and to locks and synchronization, timers and thread communication with the threading module. The multiprocessing module, which allows you to take full advantage of multiple processors on a machine comes next and finally there's the concurrent.futures module which is an abstraction layer on top of Python's threading and multiprocessing modules to simplify using them. Driscoll warns however that as it removes a lot of their flexibility it might not be the best module to use.
On the whole Mike Driscoll succeeds in making intermediate to advanced Python accessible to those who have already covered the basics. As long as you are prepared to use the code, you should gain a lot of experience by working through it.
This book isn't so much a reading book as a work book and it is worth knowing that as well as being available in Kindle format from Amazon and downloadable from Leanpub in PDF, ePub, Mobi and to be read using the Leanpub app, it has been converted into an interactive online course on the Educative website. Here it joins Python 101 and purchased of the course gives you lifetime access to the material.
See our review of Python 101 and for more recommendations of Python books see Books for Pythonistas and Python Books For Beginners
Visit Book Watch Archive for hundreds more titles.
Follow @bookwatchiprog on Twitter or subscribe to I Programmer's Books RSS feed for each day's new addition to Book Watch and for new reviews.