This doesn't work in Python 3, you can probably borrow some code from the six package to make it work with both 2 and 3.