Tweaked to run correctly on Python 2.x or Python 3.x from the same code base.

Mostly old vs new-style division, print statements, and raise/except syntax