Converting Code From Python 2 to 3: Recap
This is the last video of the course providing you a quick summary of what you have learned as well as a few tips for migration projects.
Congratulations, you made it to the end of the course! What’s your #1 takeaway or favorite thing you learned? How are you going to put your newfound skills to use? Leave a comment in the discussion section and let us know.
00:00 We’re back again and another version of Python is reported. So, this just goes to show that converting from Python 2 to Python 3 is just a matter of meticulously writing tests and then making sure those tests run in the multiple versions and then using the tools that Python provides to help you with that conversion.
00:21 Oftentimes, this will be more of a task than simply just switching around a few calls, but this goes to show the process of switching. So, change some of the problems, run the tests, fix them, and then move forward that way.
00:35
We also showed you a few ways about going about migrating—either completely convert to Python 3 or support both Python 2 and Python 3 using 2to3
via install, through Distribute, or to simply convert your source so that it runs both on Python 2 and on Python 3 without any changes.
01:00
So, we have one last thing to do, and that’s to update the setup.py
to reflect the fact that it now supports Python 3. Let’s just copy this line.
01:10 And this line is mainly a classifier so when people are looking at the library, they know that it supports Python 3. We’ll have that here, and then we’ll have all the versions, which are
01:33 Python 3.2, and… yeah. One too many we had there. And that is that! So, that concludes the screencast.
pa1 on Sept. 8, 2019
You mentioned about using six to convert py2 code to py3 and still keep it compatible with py2. But you also talked about and used 2to3 tool to do this. Are six and 2to3 different? if yes when to use six vs 2to3? What are the pros and cons of these tools?
Florian Dahlitz RP Team on Sept. 18, 2019
Hi pa1! The idea behind 2to3
is, to convert your Python 2 code to Python 3 (as the name suggests) by applying certain fixers such as making the print-statement to a print function. In contrast to that six is a library to help you make your code compatible (!) with Python 2 and 3.
Here are two hopefully helpful links:
Cynthia G Mills on June 25, 2020
The elephant in the room that you don’t mention is managing the iteration routines over dictionaries, e.g. viewitems, iteritems, … I watched this course to learn how best to approach this, since I make heavy use of dictionaries.
Become a Member to join the conversation.
Gabriel on March 15, 2019
I really don’t think the advanced tag applies to this series.