You can use one code base on Pythons 2.5 through 3.2, but it isn’t easy. You can take a look at coverage.py, which runs on 2.3 through 3.3 with a single code base.
The way to catch an exception and get a reference to the exception that works in all of them is this:
except ValueError:
_, err, _ = sys.exc_info()
#.. use err...
This is equivalent to:
except ValueError as err:
#.. use err...