Python 3 port (with Python 2.7 compatibility)

I went back and redid my initial Python 3 port, this time preserving Python 2.7 compatibility.