Some python3 fixes

These commits apply some python 3 fixes that are backward compatible with python 2.7.

I'm not sure if you want it as separate commits like I have done, or if you want me to squash the commits into one?