Errata

Python Pocket Reference

Errata for Python Pocket Reference

Submit your own errata for this product.

The errata list is a list of errors and their corrections that were found after the product was released. If the error was corrected in a later version or reprint the date of the correction will be displayed in the column titled "Date Corrected".

The following errata were submitted by our customers and approved as valid errors by the author or editor.

Color key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted By Date submitted Date corrected
Printed, PDF, ePub, Mobi,
Page 13-14
Table 1

We should update Table 1 the same way we did for Table 5-2 in Learning Python, 5th Edition -- adding cell borders, and coalescing a few rows to better indicate precedence. The revision in LP5E, from which PPR5E borrowed its Table 1, is described at both LP5E's errata page, and at:
https://www.learning-python.com/book-queries-lp5e.html#q_8

Mark Lutz
 
Nov 19, 2019 
Printed, PDF, ePub, Mobi,
Page 14
Insert at end of last bullet item in page

A minor insert to clarify how commas work in unparenthesized tuples. At the end of the final bullet item on this page (that begins "The syntax (....)"), add this single sentence, with its "comma" in italics:
"
When a tuple's parentheses are omitted, the comma separating its items acts like a lowest-precedence operator if not otherwise significant.
"

[Discussion only follows]
This is trivial when this is intended or appears standalone, but can lead to odd syntax errors in contexts where the tuple may not have been expected (e.g., in lambda return expressions). It could be argued that the comma is an operator in general, but it's a special case, as it serves this tupling role only in cases where it's not otherwise significant. It's really specific top-level separator syntax that doesn't work in contexts like function argument lists.

A new footnote and similar insert in Learning Python 5th Ed addresses this as well. The insert here adds 2 lines, but there seems ample space on the page.

Mark Lutz
 
Aug 16, 2014  Feb 06, 2015
Printed
Page 61
7th paragraph, 'file.truncate'

The text says that file.truncate "Truncates file size to, at most, size bytes" implying that the file cannot be lengthened. The docs here:

https://docs.python.org/3/library/io.html?highlight=seek#io.IOBase.truncate

say instead that it will "Resize the stream to the given size in bytes", and testing on Windows with CPython 3.5 shows that it does in fact lengthen files.

Note from the Author or Editor:
[No change required; informational only.] Your point is valid, but this is not a "serious technical mistake," and the text in question does not necessarily imply that the file cannot expand as a result of the call. It may expand to fill size bytes too, and the text does not state otherwise. I agree that this could be embelished, but it is not incorrect, and expansion is an anti-goal of this book. The full story on file.truncate is readily accessible in other resources, including Python's more complete (but more weighty) standard manuals set.

Jeremy Kelly  Oct 19, 2015 
Printed
Page 62
3rd paragraph, 'file.name'

The text says that file.name gives the 'String name of corresponding external file', strongly implying that this will be the file name. The docs here:

https://docs.python.org/3/library/io.html?highlight=seek#io.FileIO.name

say 'This is the file descriptor of the file when no name is given in the constructor', and testing on Windows with CPython 3.5 shows that it does return the file descriptor, not the file name, if a descriptor was passed to 'open'.

Note from the Author or Editor:
[No change required; informational only.] Your point is valid, but this is not a "serious technical mistake." This book is a quick-referencce resource, not an exhaustive listing of every possible option in Python programming--that would require a much larger book. In this case, the text documents the most pervasive semantics for file.name; interpretation for descriptor-based files would naturally differ, and is readily accessible in other resources, including Python's more complete (but more weighty) standard manuals set.

Jeremy Kelly  Oct 19, 2015 
Printed
Page 65
anywhere in the top 2/3 of the page, I guess

For sets, you describe (among others) the operators: < > <= >= so you may as well describe == and != also. I've tested them on 2.7 and 3.6, and they work.

Note from the Author or Editor:
[No changes required] I understand your point, but your suggestion is unfounded. The "==" and "!=" operators do not appear in any of this book's type-specific operation tables. This is intentional. Instead, these operators are listed in the preceding sections on general operations which apply to and work on all types (e.g., see Table 2 on page 16, and the text before it which notes the application to all types).

Sets call out "<", ">" and the like specially only because their meaning differs from that of all other types; "==" and "!=" do not. You may or may not concur with this organizational choice, but it works, and changing it just for sets would render the book redundant, inconsistent, and non-orthogonal (e.g., "==" and "!=" would have to also appear at lists, strings, dicts, etc.). Though tangential, these operators' class methods __eq__ and __ne__ are also covered in some depth on pages 121-122.

(Aside: I welcome input and hate to pick on an individual post, but this, as well as numerous similar posts you've made against Learning Python 5th Edition, can be fairly classified as uninformed and knee-jerk. Please review a book's content before recommending changes to it here.)

Bill Evans  Oct 20, 2019 
Printed, PDF, ePub, Mobi,
Page 73
end of 2nd paragraph, new footnote

As an afterthought, I'd like to add a brief mention of nested sequence assignments: a rare and obscure extension, covered in Learning Python 5E (see its page 343). To clarify, ADD a footnote reference to the very end of page 73's 2nd paragraph:
"""
The last four ... (3.X)").*
"""
that references the following new footnote text at the bottom of page 73, where there seems to be ample space (if not, please advise; the font of the code in this is unimportant, as we're tight on space--use whatever is most compact):
"""
* Sequence assignment also allows a nested collection of values to be assigned to a nested sequence of targets: ((a,b),c)=([1,2],3). In Python 2.X only, this pattern may also be used for function header arguments.
"""

Mark Lutz
 
Mar 18, 2014  Feb 06, 2015
Printed
Page 90
Last paragraph

"... C and C<newline>++ extensions...."
Is this the O'Reilly style for breaking "C++"? Will it be found by search in e-books?

Note from the Author or Editor:
Reprints: remove the line break in the middle of this "C++" literal. This one is so short that it shouldn't have a noticeable impact on the surrounding lines, and there are no later literals in this paragraph that may split.

Discussion: whether official style or not, line-breaks in the middle of literals is, unfortunately, common in O'Reilly books. I've raised this issue on each of mine, and pointed out the most grievous for manual repair, but some seem to slip through the cracks anyhow. The rationale is that long literals may cause prior/next lines to be too sparse or choppy if not split, and the shifting that results from fixing one may cause other later literals to be split anyhow. In this case, however, the split literal is so short that the effect of removing the line break will be harmless.

Anonymous  Jul 21, 2014  Feb 06, 2015
Printed, PDF, ePub, Mobi,
Page 92
end of 2nd paragraph

[Not an error, clarification only] The import algorithm on this page is deliberately abstract and sketchy, and fine as is. But gven that we have one line of space on this page, I'd like to add one more bit of detail.

To clarify, CHANGE the very end of this paragraph from "order:",
to the following, with "__pycache__" in filename/italics font:

"order (where step 2 involves details omitted here, including the 3.2 __pycache__ subdirectory described earlier):"

Mark Lutz
 
Mar 01, 2014  Feb 06, 2015
Printed
Page 111
last paragraph

"... __getattri<nspace><newline>bute__() method." Is this the O'Reilly style of "hyphenating" constant-width text?

Note from the Author or Editor:
Reprints: try to remove the line-break in the middle of this literal, but only if doing so does not stretch/empty the surrounding lines too much, or cause similar literal line-breaks later in this paragraph.

Discussion: whether official style or not, line-breaks in the middle of literals is, unfortunately, common in O'Reilly books. I've raised this issue on each of mine, and pointed out the most grievous for manual repair, but some seem to slip through the cracks anyhow. The rationale is that long literals may cause prior/next lines to be too sparse or choppy if not split, and the shifting that results from fixing one may cause other later literals to be split anyhow. I'm marking this one for possible repair, but only if it doesn't harm other formatting; in this case, the literal may be too long to avoid the line-break.

Anonymous  Jul 21, 2014  Feb 06, 2015
Printed, PDF, ePub, Mobi,
Page 116
1st sentence of last paragraph

[Not an error, clarification only] This section uses relative numbers to refer back to the immediately-preceding two cases of new-style inheritance precedence. It works as is, but could be mildy confusing, because there are numbered items nested in these two unnumbered cases.

To clarify, CHANGE:
"Python runs at most one (for rule 1) or two (for rule 2) tree
searches"
to:
"Python runs at most one (for instances) or two (for classes) tree
searches"

Mark Lutz
 
Mar 01, 2014  Feb 06, 2015
Printed
Page 137
5th function definition

divmod(X, Y) Returns a tuple of (X / /Y, X% Y)
*second '/' missing in printed version.

Note from the Author or Editor:
Agreed; change the referenced line from the first of the following to the second:

Returns a tuple of (X / Y, X % Y).
Returns a tuple of (X // Y, X % Y).

DISCUSSION: Technically, this builtin returns quotient and remainder as a tuple ((x-x%y)/y, x%y) in both 3.X and 2.X. A "/" is accurate in 2.X for integers (hence the typo), but "//" also applies to 3.X and other types in 2.X. See Python's manuals for more details on this call's result, especially for floats.

Anonymous  Feb 27, 2015  Nov 21, 2018
Printed, PDF, ePub
Page 208
column 2 or \ and \\ rows (rows 5 and 6)

The notation used to illustrate escapes is a bit off and line-broken poorly.

1) In column 2 of row 5 (the '\' row), change the r'\\' at the very end to r'..\..'. As is, the r'\\' per raw-string semantics really means 2 slashes which is not right, but a r'\' doesn't work either as these strings can't end in an odd number of slashes. The new r'..\..' is meant to denote a slash taken either as itself or before an escaped character that's meaningful in Python string syntax.

2) In column 2 or row 6 (the '\\ row'), there is a "\\\\" at the end of the first line that is split in half by a line break. This makes it unreadable and confusing. The "\\\\" should be forced down to the next line so all its text remains together.

Mark Lutz
 
Oct 18, 2014  Feb 06, 2015
Printed, PDF, ePub, Mobi,
Page 231
1st sentence under

[Not an error, clarification only] This sentence's parenthetical clause tersely describes shared global memory for threads. It's accurate as is given that interpreter internals covers all memory spaces, but could more explicitly allude to shared object memory--a key component of thread communication.

To clarify, CHANGE:
"(i.e., lexical scopes and interpreter internals)"
to:
"(i.e., scopes, objects, and system internals)"

Mark Lutz
 
Mar 01, 2014  Feb 06, 2015
Printed, PDF, ePub, Mobi,
Page 238
Parenthetical comment in 2nd bullet point

"tread lock auto-release" -> "thread ..."

Note from the Author or Editor:
Yes - please fix as noted (minor, especially given that this appears at the end of the book after "thread" is used often, but worth a patch).

Anonymous  Jul 17, 2014  Feb 06, 2015