Python 3 support

I ported the code to Python 3. It was actually quite easy -- your code is portable and doesn't use much Python-2-specific syntax. 

Thanks for this useful code!