Redirecting Python Logging Output for Test

A simple way to capture logging output to the screen (STDOUT) in python is monkey patch logging methods. def monkey_print(*args): print args setattr(logging, ‘info’, monkey_print) When you are done debugging delete the above code and you’re back on track. It’s not pretty, but it gets the job done fast.

Using Python Generators (a recursion example)

Recursion is a powerful programming tool, but also a tricky one. Knowing what’s going on in a recursive function at the various frame levels can be difficult which makes debugging recursive functions challenging. So below is a code snippet that uses recursion to find the largest odd factor of an input integer, and returns the … Continue reading

Python Generators vs. Closures

Generators and closures are two special function types that can come in handy under the right circumstances. To illustrate the basic usage and differences I will use some example code.   # python def inc_by_10_generator():     # returns infinite series of 10’s starting at 10 – recalls position     i = 10     while True: … Continue reading

The Vexing zlib Problem with Snow Leopard

Traceback (most recent call last): File “/usr/local/bin/virtualenv”, line 5, in from pkg_resources import load_entry_point zipimport.ZipImportError: can’t decompress data; zlib not available Seen this when working with python on OS X 10.6 (Snow Leopard)? This seemingly came out of nowhere when I wanted to set up a virtualenv on a macbook pro that hadn’t been used … Continue reading

The Scandal of Chevy Volt-Gate!

The Scandal of Chevy Volt-Gate!

Ho-hum, it’s another attack on alternative vehicles for being too expensive. Now it’s the Volt.  Then it was the Prius; the issue being that the premium for the hybrid electric vehicle did not make economic sense with gasoline below $5/gallon.  What such analyses always neglect is that a car is not a purely rational purchase … Continue reading