translate code for Python 3.x compat