Reading Update: Short Reviews

I’ve been delinquent in posting about what I’ve been reading. Rather than continue with the charade that I’ll eventually write full reviews for each book, I present a set of short reviews that should get me more or less caught up.

Tweak: Growing Up on Methamphetaminesimage0 by Nic Sheff

As part of the memoir writing class I took last fall, we read David Sheff’s book, Beautiful Boy, which tells the story of watching his promising young son struggle with drug and alcohol addiction. His son’s book, Tweak, tells his own wrenching story. When I read American Psycho a few years ago there were times I was so disturbed I sort of held the book at arm’s length and read through squinted eyes. I had the same experience with Tweak, amplified by knowing what I read was true. Tweak is not a perfect memoir — Sheff acknowledges some mistakes and missteps in the afterword — but it manages to convey the roller coaster of insanity Sheff went through as an addict, a recovering addict, and a relapsing addict. Unlike his father’s book (also very good) which mingles person narrative with facts in a journalistic memoir, Tweak is all raw emotion and craving.

The Liars’ Club: A Memoirimage1 by Mary Karr

You think your mom was crazy? No. Not at all. Mary Karr’s mom? Crazy. As in “let me set your shit on fire and come at you with a knife” crazy. And yet Karr somehow still renders her with empathy and tenderness, describing her childhood in East Texas in this, her first, memoir.

Lit: A Memoir (P.S.)image2 by Mary Karr

If The Liar’s Club let me peer into Mary Karr’s east Texas childhood, Lit, her third memoir, dropped me into her development as an adult and a poet. And consequently into her development as an alcoholic, a recovery alcoholic, and a Catholic (albeit one she describes as “not the Pope’s favorite”). I checked out Lit from the library, read it in a couple days, and then ordered my own copy. So much of the story resonated for me, and Karr’s phrasing and ear for dialogue make it a joy to read.

The Death of American Virtue: Clinton vs. Starrimage3 by Ken Gormley

A massive tome at 800 pages, Gormley’s account of Clinton’s legal troubles, beginning with Paula Jones and morphing into the Office of the Independent Council investigation, reads like a novel. Contrary to what I believed in high school, when it was all going on (and I was a Young Republican), as well as what I hear today from some more left-ist friends (that Starr was a rapid attack dog out for blood), Gormley tells a very human story. That is, a story where everyone is flawed, imperfect, and probably underestimating their own flaws. Was Clinton an incorrigible womanizer who caused massive wreckage to his life and the lives of those around him by lying? Yes. Did Starr and his office operate at the edge of their charter, with little oversight or control? Yes. Should you read this? Yes.

date:2010-06-06 18:14:22

Read: “Django 1.1 Testing and Debugging”, by Karen M. Tracey

Packt Publishing sent me a copy of `Django 1.1 Testing and Debugging <>`_ for review. I was particularly interested in reading this title, as testing is something I know makes my code better, but don’t feel like I do enough of, and because I work on a couple of Django-based projects in my spare time, with varying degrees of test coverage. While I consider myself comfortable with Python’s stock `unittest <>`_ and `doctest <>`_ modules, I was curious to learn about how you can integrate Django with other Python testing tools.

Django 1.1. Testing and Debugging is split, as the title implies, into two halves: Testing, followed by Debugging. It uses a narrative approach, following the development of a survey application throughout. The book starts with an overview of the stock unittest and doctest facilities in Python. Most of chapters 1 through 3 are devoted to the basics of unit testing, specifically for Model classes. Tracey provides information about Django-specific nuances along with way. For example, I didn’t realize Django ships with a customized doctest module to enabled ELLIPSES support in Python 2.3. Chapter 3 also provides information about how to use fixtures for providing test data, and how to specify those apart from the initial data fixtures developers may already be aware of. Chapter 4 mirrors some of the information found in Django’s testing documentation: the Django TestCase, and how you use it to do basic view testing.

Chapter 5 describes integrating Django with other tools, primarily by example. Tracey discusses how to replace the default Django test runner, and what interface the replacement needs to implement. She also provides a stub example of more “invasive” integration, crafting a new management command that could (possibly) handle code coverage reporting while running the tests. This stub was interesting, but didn’t feel particularly testing related to me. Chapter 5 closes with examples of using the excellent coverage package with django-coverage, and integrating twill into Django tests.

Chapter 6 begins the section on debugging with an overview of the Django settings that impact debugging, and how the development server supports debugging of applications. Chapter 7 follows with a thorough analysis of the development server’s error page, as well as examples of debugging based on the information given. The examples continue to develop the survey application, and introduces what Tracey describes as “typical mistakes”, then describes how to fix them.

Chapter 8 begins to dig a little deeper, and I was happy to see mention of Rob Hudson’s Django Debug Toolbar, an indispensable tool. Chapter 8 also includes details on using the logging module, and how to develop a decorator that marks function entry and exit. I know that I’m all too guilty of using print instead of logging, and it was nice to be reminded of how easy this is.

Chapter 9 was my favorite part of the book. It gives a good overview of using pdb, and then goes on to demonstrate how to use pdb and a shell session to test a race condition and deal with it.

Overall `Django 1.1 Testing and Debugging <>`_ seems like a good introductory book for Django developers who are new to testing (or Django). While many of the debugging examples seemed obvious to me, I suspect that someone new to Django could use this book as an introduction to development and debugging.

date:2010-06-06 17:42:47
tags:2010, nonfiction, read, review

Batteries Included (or, Maildir to mbox, again)

UPDATE 7 June 2010: Added usage information to docstring.

UPDATE 30 January 2012: Frédéric Grosshans has provided an updated version that supports nested maildirs; you can find it at github. YMMV.

My script for converting maildir to mbox continues to be one of the most popular pages on (according to Google Analytics). Of course, even after I updated it slightly in February, it still had a couple of bugs, likely introduced when I converted the page from MoinMoin to WordPress. This afternoon I finally decided to clear out the pending comments about those bugs, and update it.

While looking at the Python documentation for the `mailbox <>`_ package included in the standard library, I realized it could probably be simplified even further by using the library’s native `mbox <>`_ support. I’m also more comfortable using the standard library’s implementation of mbox rather than my hacked up raw file implementation (who knows, the standard library may do exactly what my script did: I’m not an mbox expert by any stretch of the imagination).

The new script is below. I should note that it’s received very little testing, and I make no guarantees. I also should note that there is nothing creative or original about this. It just uses Python’s excellent standard library. As they say, “batteries included”.

    /del> coding: utf-8

“”“maildir2mbox.pyNathan R. Yergler, 6 June 2010

This file does not contain sufficient creative expression to invokeassertion of copyright.  No warranty is expressed or implied; use atyour own risk.


Uses Python’s included mailbox library to convert mail archives frommaildir [] to mbox [] format.

See for full documentation on this library.


To run, save as and run:

$ python [maildir_path] [mbox_filename]

[maildir_path] should be the the path to the actual maildir (containing new, cur, tmp);

[mbox_filename] will be newly created.“”“

import mailboximport sysimport email

    open the existing maildir and the target mbox file
maildir = mailbox.Maildir(sys.argv [-2], email.message_from_file)mbox = mailbox.mbox(sys.argv[-1])

    lock the mbox

    iterate over messages in the maildir and add to the mbox
for msg in maildir:

    close and unlock
date:2010-06-06 13:04:29
tags:maildir, mbox, python