Learning Python - Mark Lutz [11]
7
Unbound methods
Functions (staticmethod to call via instance)
30, 31
Mixed type comparisons, sorts
Nonnumeric mixed type comparisons are errors
5, 9
There are additional changes in Python 3.0 that are not listed in this table, simply because they don’t affect this book. Changes in the standard library, for instance, might have a larger impact on applications-focused books like Programming Python than they do here; although most standard library functionality is still present, Python 3.0 takes further liberties with renaming modules, grouping them into packages, and so on. For a more comprehensive list of changes in 3.0, see the “What’s New in Python 3.0” document in Python’s standard manual set.
If you are migrating from Python 2.X to Python 3.X, be sure to also see the 2to3 automatic code conversion script that is available with Python 3.0. It can’t translate everything, but it does a reasonable job of converting the majority of 2.X code to run under 3.X. As I write this, a new 3to2 back-conversion project is also underway to translate Python 3.X code to run in 2.X environments. Either tool may prove useful if you must maintain code for both Python lines; see the Web for details.
Because this fourth edition is mostly a fairly straightforward update for 3.0 with a handful of new chapters, and because it’s only been two years since the prior edition was published, the rest of this Preface is taken from the prior edition with only minor updating.
About The Third Edition
In the four years between the publication of the second and third editions of this book there were substantial changes in Python itself, and in the topics I presented in Python training sessions. The third edition reflected these changes, and also incorporated a handful of structural changes.
The Third Edition’s Python Language Changes
On the language front, the third edition was thoroughly updated to reflect Python 2.5 and all changes to the language since the publication of the second edition in late 2003. (The second edition was based largely on Python 2.2, with some 2.3 features grafted on at the end of the project.) In addition, discussions of anticipated changes in the upcoming Python 3.0 release were incorporated where appropriate. Here are some of the major language topics for which new or expanded coverage was provided (chapter numbers here have been updated to reflect the fourth edition):
The new B if A else C conditional expression (Chapter 19)
with/as context managers (Chapter 33)
try/except/finally unification (Chapter 33)
Relative import syntax (Chapter 23)
Generator expressions (Chapter 20)
New generator function features (Chapter 20)
Function decorators (Chapter 31)
The set object type (Chapter 5)
New built-in functions: sorted, sum, any, all, enumerate (Chapters 13 and 14)
The decimal fixed-precision object type (Chapter 5)
Files, list comprehensions, and iterators (Chapters 14 and 20)
New development tools: Eclipse, distutils, unittest and doctest, IDLE enhancements, Shedskin, and so on (Chapters 2 and 35)
Smaller language changes (for instance, the widespread use of True and False; the new sys.exc_info for fetching exception details; and the demise of string-based exceptions, string methods, and the apply and reduce built-ins) are discussed throughout the book. The third edition also expanded coverage of some of the features that were new in the second edition, including three-limit slices and the arbitrary arguments call syntax that subsumed apply.
The Third Edition’s Python Training Changes
Besides such language changes, the third edition was augmented with new topics and examples presented in my Python training sessions. Changes included (chapter numbers again updated to reflect those in the fourth edition):
A new chapter introducing built-in types (Chapter 4)
A new chapter introducing statement syntax (Chapter 10)
A new full chapter on dynamic typing, with enhanced coverage (Chapter 6)
An expanded OOP introduction (Chapter 25)
New examples