Python 3 compatibility

The (hopefully) trivial parts of #358 which should not result in any regression...