|Page 21. Factual error.
||In the second paragraph replace "and
remove() which removes an item at a given index position." with
"and remove() which removes the given item." Later references
to the list.remove() method are correct.
|Page 61. Naïve floating-point comparison.
||The equal_float() function shown on
this page is simple and standard, but it doesn't work well when the
numbers compared have very different magnitudes. Here's an improved
def equal_float(a, b):
return abs(a - b) <= (sys.float_info.epsilon * min(abs(a), abs(b)))
The examples' Util module has an equal_float()
function that takes an optional third argument—the number of
decimal places to compare to.
|Page 68. Mistake re `ä' ordering.
||The second from last paragraph says that in German
`ä' is sorted as if spelled `æ': this should be qualified
since it is only true of German phonebooks; in German dictionaries it is
sorted as plain `a'.
|Page 73. Incorrect method description.
||Change the last three words in table 2.8's
s.isdigit() description to “a Unicode digit”.
|Page 83. Duplicate word.
||The last sentence of the first paragraph of
the Format Specifications subsection begins “The the”—this should
simply be “The”.
|Page 134. Code error in the text.
||In the second paragraph (immediately after the
greens example), I say: "Here, using mapping unpacking
(**) has exactly the same effect as
writing .format(green=greens.green, olive=greens.olive,
lime=greens.lime)". That would be true if greens was an
object with those attributes, but in fact it is simply a dict
with those keys, so the correct code is:
|Page 144. Wrong word.
||The first line on this page contains the
phrase "a number that cannot be less than"; change "less" to "more" to
correct the meaning.
|Page 202. Subtle code error.
||The relative import shown in the right hand
code snippet is incorrect—but unfortunately, due to a bug in
Python 3.0.0–3.1.2, it actually works. It doesn't work from
Python 3.1.3 though, so should be replaced with from
.. import Png (which means import the Png module from the
module two directories—because there are two dots—above this
one, i.e., from the Graphics module). This correction has been
applied to the downloadable archives.
|Page 215. Additional note.
||The optparse module discussed here is
deprecated in Python 3.2; it has been superceded by the
argparse module. The book's examples continue to use
optparse so that they work with all Python 3.x
versions. Stick with optparse if you need to maintain backward
compatibility with Python 3.1; otherwise switch to
argparse which is better (and easy to switch to).
|Page 235. Spurious word.
||In the section “Object-Oriented Concepts and
Terminology”'s first paragraph's third sentence, replace
the phrase “data type in later in this section,” with
“data type later in this section,”
|Page 238. Typo.
||The last sentence should end “is shown here:”,
not “is show here:”.
|Pages 270–275. Subtle bug.
||The SortedList.py module (and various
alternative versions such as SortedListAbc.py), have a subtle
bug that causes incorrect behavior if the key function folds case (e.g.,
lambda x: x.lower()) and there are multiple values which
have the same keys (e.g., "abc" and "ABC"). The
algorithms used in the methods shown in the book are correct, but many
of the methods must be changed to account for this use case. The
necessary corrections have been applied to the downloadable
|Page 377. Subtle code and explanation
||Replace the penultimate paragraph's last
sentence (beginning "It stores the setter method"), with
"It stores the setter method it has been given
(which can now be used in the __set__() method), and returns the
descriptor itself, since it is the descriptor through which the instance
data is accessed."
Also, replace the last line of the setter() method (return
self.__setter) with return self.
|Page 481. SQLite syntax variation.
||The SQLite SQL used to create the tables shown
on this page uses the keyword AUTOINCREMENT. For some
versions of SQLite this keyword is a syntax error. If this is the case
for your version of SQLite simply delete the keyword—you will
still get autoincrementing since for versions of SQLite that don't
accept AUTOINCREMENT, the use of INTEGER PRIMARY KEY
|Pages 534–553. PyParsing update.
||The book uses PyParsing version 1.5.2 which
was current at the time of writing. Version 1.5.5 has introduced some
changes—for example, the module is now pyparsing for both
Python 2 and Python 3 (before it was pyparsing_py3
for Python 3). The other changes are bug fixes, enhancements, and
additional examples, so apart from the import, everything in the book