Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
The road ahead - Python 3

The Tracks to Albany beside the Hudson A couple of days ago, I mentioned Python 3 in general terms - and today I'm starting to flesh out the road ahead.


The print operator in Python was always a bit curious, with the trailing comma to signify "no new line" ... and that has been replaced by a print function, with named parameters for the end of line action, parameter separator, and output file - it's much more flexible in it sown right, and it allows you to override the printg function which you could not do with an operator. Here are some sample print function calls:

print (teeth,"teeth and",coal,"shoes")
print (teeth,"teeth and",coal,"shoes",sep = " - ")
print (teeth,"teeth and",end = "")
print (coal,"shoes")
print ("Error and logging message",file = sys.stderr)

See complete Python 3 example and Python 2 equivalent

input and raw_input

The input function, which used to process what the user typed through the Python interpreter has gone (thank goodness!) and the old raw_input functionality, that did what we wanted 99.9% of the time for input has now simply been named input. This will be short term confusing, but a big relief in the medium and long term.

See complete Python 3 example and Python 2 equivalent

range and xrange

The original range function - many moons ago - returned a list, which you could then step through in a for loop. Which was great for a small list and really grotty for a longer one - rather like blowing up a balloon (generating a list) and then letting the air out of it slowly. And of course, if you blow a balloon up too much it bursts! The xrange function was added to provide an iterator - rather than blowing up a balloon, the information is generated just-in-time, very much like a generator

Moving on to Python 3, range is now a generator (and xrange has gone), which means that it will default to being tidy. The same applies to things like map as well, and you will need to add a list function call there if you don't want to iterate through a mapping

Here's a generator in use (in Python 3) with the range function itself producing an iterator:

def squares(g):
  for val in range(g):
    print ("working out ",val)
    yield val*val
for ref in squares(8):
  print ("Board with ",ref," squares")

and here is what that code would look like on Python 2:

def squares(g):
  for val in xrange(g):
    print "working out ",val
    yield val*val
for ref in squares(8):
  print "Board with ",ref," squares"

Our next public Python Course will include a module on Python 3 changes, covering not only the new features, but also the way to make best use of them and to plan for them and easily convert from legacy Python code - moving Python forward on a practical basis. In due course (estimate - 3 to 6 months, depending on market requirements) the whole course will be Python 3 based.

We can also provide a one day seminar for current python users, introducing them to the new facilities and changes and helping them plan a painless transition for the way forward. Please email me for details.
(written 2008-09-10, updated 2008-09-11)

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
  [4470] Testing in Python 3 - unittest, doctest and __name__ == __main__ too. - (2015-04-21)
  [4469] Sorting in Python 3 - and how it differs from Python 2 sorting - (2015-04-20)
  [2871] Moving from Python 2.6 to Python 3 - (2010-07-14)
  [2778] Learning to program in Python 2 ... and / or in Python 3 - (2010-05-24)
  [2559] Moving the product forward - ours, and MySQL, Perl, PHP and Python too - (2010-01-01)
  [2285] Great new diagrams for our notes ... Python releases - (2009-07-13)
  [2277] Python classes / courses - what version do we train on? - (2009-07-10)
  [1788] Python 2 to Python 3 / Python 3000 / Py3k - (2008-09-07)
  [753] Python 3000 - the next generation - (2006-06-09)

Back to
Sharing variables with functions, but keeping them local too - Python
Previous and next
Horse's mouth home
Forward to
All the pieces fall into place - hotel and courses
Some other Articles
What have iTime, honeytrapagency and domain listing center got in common?
Refactoring - a PHP demo becomes a production page
Which country does a search engine think you are located in?
All the pieces fall into place - hotel and courses
The road ahead - Python 3
Sharing variables with functions, but keeping them local too - Python
Looking for a value in a list - Python
Howto - write and manage a news box on your web page
Picturing the rain
4571 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 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., 2015: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/1791_The ... hon-3.html • PAGE BUILT: Thu Sep 18 15:30:25 2014 • BUILD SYSTEM: WomanWithCat