Fix python3 support

Python3 support was broken, because of several places where was used
python2 syntax, that is incompatible with the syntax of python3.