Apply some syntax changes accepted by Python 2 as well as Python 3

Use 2to3 to make some syntax changes for Python 3 that are also accepted
by Python 2.

- Use except ... as
- Use 'in' instead of has_key
- Use repr instead of backticks
- Use '.' for relative imports
- Replace '<>' with '!='