Several py3 fixes.

Last big PRs reintroduce some py3 incompatibilities, so I fixed all the errors except for two failing test in both environments (Issue #472). I also update the short files accordingly with PEP8 (reasonable, not strict way).