/* jquery */ /* jquery accordion style*/ /* jquery init */

27 October 2014

Python 2 to 3 Conversion Tips

Even a well loved language like Python has its downsides.
One tricky issue is that there are two main Python versions, namely 2 and 3.
And, unfortunately, version 2 code often fails to run in a Python 3 environment, and visa versa.

So here's my quick guide.

Key Elements

The focus of your conversion efforts should be on:
• print and print()
• exception handling
• module import errors
• integer handling
• unicode characters
• using bytes

There's a very helpful guide on each of this topics at the Python 3 porting site.
And more useful information can be found on this blog page from Alexandre Vassalotti.

No Conversion Required

Do you what to make write code that works in both versions?
Then head over to the no conversion chapter and find out how the Six utility works its magic.

Check out my free Learn Python on the Raspberry Pi tutorial.