Last month around the time of PyCon USA 2012, Matt Harrison sent me a copy of his newest book, Guide to: Learning Iteration and Generators in Python. I’ve been wanting to learn more about generators anyway, so I thought this was pretty fortuitous. Sadly, it took me a month to get around to reading it. The eBook weighs in at 460 kb for the mobi (i.e. Kindle) version or 240 for the epub. We’ll take a quick look at the good and the bad after the jump.
This is a very technical book. I think if it were printed, it would run around 50 pages though. So it’s a quick read. Plus it retails for only $3.99 on Amazon. I would say that this book is for intermediate to advanced Python programmers in that the author uses a lot of highly technical terminology and digs under the covers of Python itself, especially in the first few chapters. He also doesn’t spend a lot of time explaining trivial stuff, so I think this would serve as a good template for the vaunted “extreme” talk track at PyCon these days. Most importantly to me is that the book showed me where I could actually implement generators in code I was creating that very day. I just thought that was cool! You also learn the difference between iterators and iterables, which was a little mind boggling.
The author didn’t say he was sending me a rough draft, but I think that’s what I received. What I mean by that is that there are a lot of little sentence issues where you’ll see things like a “the” instead of a “than” or a sentence that’s missing a “the”, “an” or “a”, which can make the sentence awkward to read. I found the first couple examples a little confusing as the author uses a while loop to describe a for loop. The main confusing bit was that he was referring to a while loop as it were the previous for loop example. One of the funnier mistakes was this quote:
Sites such as Stack Overfull are choke full of answers claiming that xrange is a generator. (Kindle Location 403)
I wasn’t able to find an errata page for the book so I can’t say if these little nitpicky things have been fixed. Because the book is pretty technical, this isn’t really the best way for a beginner to learn generators either. On the other hand, sometimes it IS good to learn the hard way first. If you’re struggling with understanding generators or wonder why they even exist, then I think this book will help you out. Otherwise you can always check out the documentation.
Guide to: Learning Iteration and Generators in Python
By Matt Harrison