Support python3

This could do with some testing to ensure it didn't break anything / works correctly in python3.

These changes make the syntax compatible with python 3x and python2