Cameron Laird interviews Doug Hellmann, author of The Python Standard Library by Example , about his first encounters with Python, his work on Python Module of the Week, and what he's learned from other books.



It's evident that Doug Hellmann cares more about the success of his readers than the success of his book. During an interview with Doug by long-time InformIT contributor Cameron Laird about the upcoming release of The Python Standard Library By Example, he consistently turned the conversation toward the riches of Python and away from his own contributions. Read for yourself in these excerpts from an e-mail dialogue between Doug and Cameron.

In The Beginning

Cameron Laird: Do you remember how you first encountered Python?

Doug Hellmann: My friend, Dick Wall, introduced me to Python as a scripting language for building internal tools while we were working together at a GIS software company some time between 1996 and 1998. I was in charge of maintaining the build and porting the application, written in C, to run on AIX and the DEC Alpha under their 64-bit UNIX. Python quickly became my favorite language for cross-platform automation, and I used it to manage parts of the build, create test harnesses, and even to generate release notes documents from the bug database. This was all before wide-spread adoption of Web-based user interfaces, so I was doing a lot of command line and Tkinter development, depending on the need at the time.

Cameron: How did the writing start? When did you begin PyMOTW?

Doug: I started blogging in late 2006, and applied myself to it seriously beginning in 2007. The "module a week" theme started in 2007 and served two purposes. First, it gave me something to write about every week, so I could build up the personal practice of writing on a regular basis. Second, it had been several years since I had taken a serious look at the standard library, and I knew there had been changes and additions in that time. Going through the library module by module to write examples gave me a structure for studying the changes and enhancements, and for digging deeper into the modules that I had used only lightly in my projects.

Cameron: Do you personally contribute code back to Python?

Doug: I have commit access, and have contributed a couple of small patches to the CPython documentation. Most of my contributions to the community have come in the form of stand-alone projects such as virtualenvwrapper or writing for PyMOTW, Python Magazine, and now the PSF blog.

Cameron: You choose what will help you improve as a writer: why?

Doug: I enjoy the challenge of organizing information and presenting it clearly in writing. There are a lot of similarities between writing and programming, but writing has aspects of teaching and information sharing that is fulfilling in a different way.

Cameron: When you began PyMOTW in 2007, did you regard "the standard library" as immutable, in a programming sense, or was one of your aims to track what was happening with Python3000, IronPython, and so on?

Doug: There was no question in my mind that the standard library was a moving target. I knew that I would have to go back and address those changes, eventually. It also meant there would be entirely new modules, but since I was covering Python 2.x, that did not come up as often as smaller additions and changes. Part of the work I did during the editing phase for the book was to review every module to make sure all of the important aspects are covered and verify that all of the examples work under Python 2.7. That review resulted in updates in a few cases, and even a couple of bug reports for regressions from 2.6 or 2.5, when the examples were originally written.

I have not focused on the other implementations of Python, so far. The recent discussions about versioning the standard library separately from the CPython implementation should make it easier for the implementations both to be consistent, and to identify clearly any lingering inconsistencies. I hope that means less work for all Python authors—and improved compatibility for developers!

Heart of Python

Cameron: To me, what you write is at the heart of Python action. In school, languages are generally taught with an emphasis on syntax—students come out roughly equating "I know language $N" and "I'm familiar with the syntax of $N". This misses how much of of real engineering practice has to do with intimacy with the (run-time) library. For me, therefore, Standard Library is not just a good book, or a well-written one, but an important one.

Doug: I feel the same way about the standard library as the source of much of Python's usefulness as a tool. Unfortunately, the library is so big that a lot of programmers never have (or take) the time to look beyond the modules they have to use, like os and sys . That means they miss out on some of the really interesting parts, like collections and multiprocessing.

Cameron: Have there been any surprises for you in reader reactions? Are they finding something in the book that you didn't expect?

Doug: It has been fun to see which examples people find the most helpful. Some of the modules I considered "simple" have had the best responses, which makes me glad that I included them. As far as finding unexpected nuggets, I think that has gone the other way. There have been a few cases in which readers pointed out simpler idioms for examples, and several gave me links to third-party modules I had not seen ( dateutil and cmd2 come to mind as specific examples). So in addition to the knowledge I gained researching and writing, I also have been learning from their feedback.

Cameron: What did you learn from other books?

Doug: I discovered Python Standard Library as I was preparing the proposal for my own book. I don't know how it could be that I had never seen it before then. I skimmed a copy, but by then most of my writing was done so I did not use it as a reference. I did use David Beazley's Python Essential Reference several times, and have kept a copy of that on my desk since the first edition. I don't have any of Alex Martelli's books, although my impression is that Python Cookbook would be complementary to The Python Standard Library By Example .

Cameron: Like Python itself, Standard Library seems deliberately "stripped-down". All the emphasis is on use of the standard library.

Doug: That was very deliberate. Compiling The History of the Python Standard Library easily could take as much effort as creating all of the examples for this book did! In all seriousness, many of the modules are complicated enough that I wanted to keep the focus on explaining their purpose and showing how to use them successfully. I did not want to become side-tracked with discussions of older implementations or design changes through time. There are one or two places where I do discuss the reason that the library includes several modules that perform the same function (command line argument parsing comes to mind as an example). I don't dwell on details, but I do try to point out how to choose which module to use, when there is a choice to be made.

I decided early on that I was not going to write an introductory text, for a couple of reasons. First, there are far more books available for beginners than intermediate and advanced programmers. I wanted to create a resource for someone ready to take the next step and stretch their abilities. While the book is not devoid of exposition, I did try to make all of the examples stand on their own, though comments, variable naming, and structure. I worked on the size of the programs to keep them small enough that they can be understood without having to pull in material from several modules at a time, while still being large enough that they are useful as "real" examples.

My second consideration was scope. The sheer breadth of topics covered in the standard library means that beginning with the absolute basics for every module would have required writing an entire shelf full of books. The math and networking topics alone would each fill a volume equal in size to this one. My goal was to find the intersection between knowing Python and the domain-specific knowledge addressed by each module. For readers approaching these topics for the first time, I have included brief introductions and lists of references where they can find more details. If I have struck the right balance, the text should be useful both to a Python programmer learning about an application area and to a programmer with some domain knowledge coming from another language.

I don't want to give anyone the impression that they need a huge amount of knowledge to get value from, or to understand, the book. The examples are meant to stand on their own, but I do recognize that readers will have different levels of experience based on the situations they have encountered in their careers so far. I had to do a fair amount of research myself, so I include all of the references I found useful, in case they want more background on a given subject.

This project has definitely given me a much greater appreciation for the amount of foundation work already done by the core developers in building the standard library. Python is not just a language, it's a development platform.

For the Reader

Cameron: What do you know about how readers are approaching the book? Are they treating it as a reference only? Do they try to read it systematically, to learn all of Python?

Doug: I tried to group related topics together, and then order them logically so that someone reading straight through would be building on earlier knowledge. But I don't expect most readers to approach it that way. It is also accessible for someone wanting to "dip in" to find or learn about a single module, or just refer back to a section to refresh their memory. Between the table of contents, the module index, and the topic index there are a lot of ways to jump directly to the nugget of information you're seeking.

Cameron: When can readers get their hands on it?

Doug: It's available for pre-order through online sites now, with delivery scheduled for June. I believe it will be in stores by June, too.

Cameron: What plans do you have for the future?

Doug: I do plan to resume publishing PyMOTW. The next step is to port the existing examples to Python 3. I have begun researching some of what I will need to know for that process, but have not started the coding work, yet. I also have some other unrelated topics that I plan to write about in shorter articles, and I may tackle them first. I will be posting them to DougHellmann.com or on InformIT.