| Programming in Python 3 (Second Edition) Errata ISBN-10: 0321680561 – ISBN-13: 978-0321680563 |
|
| Second Edition: Errata for All Printings | ||
| Issue | Resolution | Reporter |
| 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
version:
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.
|
William Jones |
| 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: .format(green=greens["green"], olive=greens["olive"], lime=greens["lime"]). | Clemens Kaposi |
| 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. | Iama Netizen |
| Page 377. Subtle code and explanation error | 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. |
Luca Boasso |
| 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 remains valid. | Author |
| Second Edition: Errata for the First Printing only (additional to the errata above—these are all fixed in the Second and subsequent printings) | ||
| Issue | Resolution | Reporter |
| Page 34. Incorrect output. | At the bottom of the page, change each occurrence of "number" in the output to "integer". | Algis Kabaila |
| Pages 89 & 95. Update to footnote info. | The footnotes on these pages point out the Window's console's poor UTF-8 support and notes that alternative examples (print_unicode_uni.py and quadratic_uni.py) are provided to work around this. Now Glenn Linderman has found a solution (that I've tested successfully with Python 3.1); see Python Bug 1602/message #94445. If the solution is followed, Windows users can use the same print_unicode.py and quadratic.py programs as Linux and Mac OS X users and see the same characters output. (Be aware though, that this may cause problems executing other programs in the console, so for anything else it is probably best to use a separate console.) | Author |
| Page 90. Bug fix. | The print_unicode() function has a
subtle bug. Replace the line:
end = sys.maxunicodewith the line: end = min(0xD800, sys.maxunicode) # Stop at surrogate pairsThis is because Python can't handle surrogate pairs and some of them start at code point U+D800. This correction has been applied to the downloadable archives. |
Hugo Gagnon |
| Page 258. Clarification. | In the description of the reimplementation of
the __repr__() method I say that it is necessary to call
super().__repr__() to access the base class's
__repr__() method without causing infinite recursion. That
reason is true in general, but not in this particular case. Nonetheless,
the code shown is correct. What I should have said is this:
"For the str.format()'s second argument we cannot just pass self. There are two reasons for this. First, if we use self, Python will format it using the __str__() method if that is present in this class or (as in this case) in one of its base classes, whereas we want the representational format rather than the string format. And second, if there is no __str__() implementation, Python will fall back to using __repr__(), thus leading to infinite recursion. By calling the base class's __repr__() method we ensure that we get the representational format and at the same time avoid depending on whether or not a __str__() method happens to be implemented." |
Luca Boasso |
| Page 454. Incorrect URL. | In the second paragraph, change the URL to code.google.com/p/python-safethread. | Takahiro Nagao |
| Page 495. Incorrect footnote. | Change the footnote to: "Note that only numbered backreferences can be used inside character classes, that is, inside []." |
Steve Andrews |
| Page 511. Incorrect sentence. | The last sentence of the first paragraph after
the code snippet is incorrect. Change it to: "This is not easy, especially since only numbered backreferences can be used inside character classes." |
Steve Andrews |
Copyright © 2009-10 Qtrac
Ltd. All Rights Reserved.
|