python3 compatibility inspired by waaaaargh (Johannes Firlefanz)