Python 3 compatibility

I'm currently using python3, so I made some compatibility changes.
It doesn't seem to break python2-compatibility.
Maybe you want to merge those changes.