The following specific changes were made in the Python 2.X and 3.X lines after the fourth edition was published, and have been incorporated into this edition. Specifically, this section documents Python book-related changes in Pythons 2.7, 3.2, and 3.3.
On the technical front, Python 2.7 mostly incorporates as back-ports a handful of 3.X features that were covered in the prior edition of this book, but formerly as 3.X-only features. This new fifth edition presents these as 2.7 tools as well. Among these:
Set literals:
{1, 4, 2, 3, 4}
Set and dictionary comprehensions:
{c * 4 for c in 'spam'}, {c: c * 4 for c in 'spam'}
Dictionary views, incorporated as optional methods:
dict.viewkeys(), dict.viewvalues(), dict.viewitems()
Comma separators and field autonumbering in str.format (from 3.1):
'{:,.2f} {}'.format(1234567.891, 'spam')
Nested with statement context managers (from 3.1):
with X() as x, Y() as y: ...
Float object repr display improvements (back-ported from 3.1: see ahead)
To see where these topics are covered in the book, look for their entries in the 3.0 changes list of Table C-1, or the Python 3.1 changes section, both ahead. They were already present for 3.X, but have been updated to reflect their availability in 2.7 as well.
On the logistical front, per current plans 2.7 will be the last major 2.X series release, but will have a long maintenance period in which it will continue to be used in production work. After 2.7, new development is to shift to the Python 3.X line.
That said, it’s impossible to foresee how this official posture will stand the test of time, given 2.X’s still very wide user base. See the preface for more on this; the optimized PyPy implementation, for example, is still Python 2.X only. Or, to borrow a Monty Python line, “I’m not dead yet...”—stay tuned for developments on the Python 2.X story.
Python 3.3 includes a surprisingly large number of changes for a point release. Some of these are not entirely compatible with code written for prior release in the 3.X line. Among these, the new Windows launcher, installed as a mandatory part of 3.3, has broad potential to break existing 3.X scripts run on Windows.
Here’s a brief rundown of noteworthy 3.3 changes, along with their location in this book where applicable. Python 3.3 comes with:
A reduced memory footprint that is more in line with 2.X, thanks mainly to its new variable-length string storage scheme, and also to its attribute name-sharing dictionaries system (see Chapter 37 and Chapter 32)
A new namespace package model, where new-style packages may span multiple directories and require no __init__.py file (see Chapter 24)
New syntax for delegating to subgenerators: yield from ... (see Chapter 20)
New syntax for suppressing exception context: raise ... from None (see Chapter 34)
New syntax for accepting 2.X’s Unicode literal form to ease migration: 3.3 now treats 2.X’s Unicode literal u'xxxx' the same as its normal string 'xxxx', similar to the way 2.X treats 3.X’s bytes literal b'xxxx' the same as its normal string 'xxxx' (see Chapter 4, Chapter 7, and Chapter 37)
Reworked OS and IO exception hierarchies, which provide more inclusive general superclasses, as well as new subclasses for common errors that can obviate the need to inspect exception object attributes (see Chapter 35)
An all-web-browser-based interface to PyDoc documentation started via pydoc -b, replacing its former standalone GUI client search interface, which was in the Windows 7 and earlier Start button and invoked by pydoc –g (see Chapter 15)
Changes to some longstanding standard library modules, including ftplib, time, and email, and potentially distutils; impacts in this book: time has new portable calls in 3.X (see Chapter 21 and Chapter 39)
An implementation of the __import__ function in importlib.__import__, in part to unify and more clearly expose its implementation (see Chapter 22 and Chapter 25)
A new capability in the Windows 3.3 installer that extends the system PATH setting to include 3.3’s directory as an install-time option to simplify some command lines (see Appendixes A and B)
A new Windows launcher, which attempts to interpret Unix-style #! lines for dispatching Python scripts on Windows, and allows both #! lines and new py command lines to select between Python 2.X and 3.X versions explicitly on both a per-file and per-command basis (see the new Appendix B)
Python 3.2 continued the 3.X line’s evolution. It was developed during a moratorium on 3.X core language changes, so its relevant changes were minor. Here’s a quick review of major 3.2 changes, and their location in this fifth edition where relevant:
Byte-code files storage model change: __pycache__ (see Chapter 2 and Chapter 22)
The struct module’s autoencoding for strings is gone (see Chapter 9 and Chapter 37)
3.X str/bytes split supported better by Python itself (not relevant to this book)
The cgi.escape call was to be moved in 3.2+ (not relevant to this book)
Threading implementation change: time slices (not relevant to this book)