Switch code to Python 3