Converted to python 3

Ran 2to3 then fiddled with the rest of the conversion until it worked.