Some python3 fixes

These commits applies 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?