Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
Convering from Python 2 to Python 3 - an update, and the 2to3 utility

Python 3 has now been with us for a number of years, but the move across from Python 2 to Python 3 is still far from complete. And as Python 3 is not source code compatible with Python 2, that's no big surprise to anyone. The very good reason for the changes is that the correct decisions made on langauge syntax in 1988 would not be the correct decisions for the language for 2018 or 2028, but there's a huge user bas of code out there which people have invested in and need to maintain and keep running, and a huge number of modules and packages that need to be converted and tested before end user programmers can make full use of them.

In order to help with the move in the future - so that Python 2 support can eventually (2019?) be phased out, some of the new facilities have been backported to Python 2. The new format method on a string, for example, and the with keyword. But some things cannot be easily backported.

Recommmendation is that you stick with developmement in 2.7 while you are still supporting Python 2 strema machines, writing your code with an eye on Python 3. It is possible to write code that will compile and run in both - our json parser demo is an example - but there are time that's not the optimum thing to do.

Supplied with Python3 is a utility called 2to3 which will do a lot of the work for you; be wary though, because there are some changes in a dynamic language like Python which it's simply not possible to automate.

Here's an example of 2to3 in use:

 WomanWithCat:q2 grahamellis$ 2to3 -w dx
 RefactoringTool: Skipping implicit fixer: buffer
 RefactoringTool: Skipping implicit fixer: idioms
 RefactoringTool: Skipping implicit fixer: set_literal
 RefactoringTool: Skipping implicit fixer: ws_comma
 RefactoringTool: Refactored dx
 --- dx (original)
 +++ dx (refactored)
 @@ -19,9 +19,9 @@
  edges = getEdges(width,height,depth)
  corners = getCorners(width,height,depth)
 -print "Our",what,"is",width,"by",height,"by",depth
 -print "Volume is",volume
 -print "Surface ares is",surface
 -print "Edge length is",edges
 -print "Corners",corners
 +print("Volume is",volume)
 +print("Surface ares is",surface)
 +print("Edge length is",edges)
 RefactoringTool: Files that were modified:
 RefactoringTool: dx

And here's a note of the changes it's made:

 WomanWithCat:q2 grahamellis$ diff dx dx.bak
 < print("Our",what,"is",width,"by",height,"by",depth)
 < print("Volume is",volume)
 < print("Surface ares is",surface)
 < print("Edge length is",edges)
 < print("Corners",corners)
 > print "Our",what,"is",width,"by",height,"by",depth
 > print "Volume is",volume
 > print "Surface ares is",surface
 > print "Edge length is",edges
 > print "Corners",corners
 WomanWithCat:q2 grahamellis$

Our public Python Courses are moving from Python 2 to Python 3 over the next year; examples are run in both at present and that will continue, but the bias will switch - and with typical group sizes being just three or four delegates, I'm well able to tailor the presentation to suit the group.

Private courses are run using Python 2, or Python 3, after a discussion with the technical lead prior to the course. Almost inevitably, any courses in Python 2 will have a strong element of "do it this way to prepare for the future" about them, but it's rare for a course to be jumping back and forth between every example as that serves more to baffle than to clarify!
(written 2016-10-30)

Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
Y300 - Python 3 - What is new, what's changed and why
  [753] Python 3000 - the next generation - (2006-06-09)
  [1788] Python 2 to Python 3 / Python 3000 / Py3k - (2008-09-07)
  [1791] The road ahead - Python 3 - (2008-09-10)
  [2277] Python classes / courses - what version do we train on? - (2009-07-10)
  [2285] Great new diagrams for our notes ... Python releases - (2009-07-13)
  [2559] Moving the product forward - ours, and MySQL, Perl, PHP and Python too - (2010-01-01)
  [2778] Learning to program in Python 2 ... and / or in Python 3 - (2010-05-24)
  [2871] Moving from Python 2.6 to Python 3 - (2010-07-14)
  [4469] Sorting in Python 3 - and how it differs from Python 2 sorting - (2015-04-20)
  [4470] Testing in Python 3 - unittest, doctest and __name__ == __main__ too. - (2015-04-21)
  [4590] Progress on moving from Python 2 to Python 3 - training for both versions - (2015-12-01)
  [4649] Object and Static methods - what is the difference; example in Python 3 - (2016-02-17)
  [4650] Why populate object with values as you construct them? - (2016-02-18)
  [4712] A reminder of the key issues to consider in moving from Python 2 to Python 3 - (2016-10-30)

Back to
Searching a Json or XML structure for a specific key / value pair in Python
Previous and next
Horse's mouth home
Forward to
A reminder of the key issues to consider in moving from Python 2 to Python 3
Some other Articles
Well House Manor - Still five out of five!
The technical article feed continues - personal updates more proactive on Facebook now!
Equality (in Python)
Convering from Python 2 to Python 3 - an update, and the 2to3 utility
Searching a Json or XML structure for a specific key / value pair in Python
Some gems from Intermediate Python
Scons - a build system in Python - building hello world
Some gems from an introduction to Python
Melksham trial train service is to be made permanent
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page

This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2023: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4711_Con ... ility.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb