Make Python scripts compatible with Python 3

Continuing where #303 left off.