Errata

Python in a Nutshell

Errata for Python in a Nutshell

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
Page Page 457
Table 15-9 (SimpleQueue part)

In Table 15-9, the SimpleQueue is described as "an unbounded FIFO queue lacking the methods full, task_done, and join (see Table 15-10)" which suggests that these methods are listed in 15-10, but only the method full is listed there. The task_done and join methods are only explained in the text surrounding the table.

Note from the Author or Editor:
Thanks for submitting. In many of the tables in the book, we could not list every related item for each class or module, else the book would easily exceed 900 pages. And so we would choose selected items to include, and direct the reader to online resources for more complete docs; that is the case for this table as well.

To help minimize the confusion described in this erratum, we propose changing the description in Table 15-9 to "an unbounded FIFO queue lacking the methods full, task_done, and join (see Table 15-10 and the following text)".

Ivo Grondman  Mar 07, 2023 
Page p156
last section

in methods list, missing method `__rtruediv__` after `__radd__`

Note from the Author or Editor:
The list of method names should read in this order:
__radd__, __rfloordiv__, __rmod__, __rmul__, __rsub__, __rtruediv__, __rmatmul__

In the description, the first sentence should start "The operators y+x, y//x, y%x, y*x, y-x, y/x, y@x respectively call these methods on x..."

Tim Stamp  Aug 25, 2023 
Printed, O'Reilly learning platform
Page 59
Code example beginning with "re_match ="

Regular expression should be `r'Name: (\S+)` to capture a full name (currently just captures the first character). Occurs in 2 places in this code example.

Paul McGuire
 
Nov 26, 2023 
Page 254
table entry for "filter" function

Parantheses are not "paired":

(item for item in seq if func(item)

either missing closing, or opening paranthesis is unnecessary.

Note from the Author or Editor:
Thanks for submitting this. We should add a closing parenthesis at the end of this line, so that it reads "(item for item in seq if func(item))".

Marek Włodarz  Sep 05, 2023 
Printed
Page 256
Description of "map()" function

The code examples for map() read as:
-------
For example, map(func, seq) is just like the generator expression:

(func(item) for item in seq).map(func, seq1, seq2)

is just like the generator expression:

(func(a, b) for a, b in zip(seq1, seq2))
-------


The first snippet is in error, and should be merged with the intervening text, as follows:
-------
For example, map(func, seq) is just like the generator expression:

(func(item) for item in seq)

map(func, seq1, seq2) is just like the generator expression:

(func(a, b) for a, b in zip(seq1, seq2))
-------



Paul McGuire
 
Dec 11, 2023 
Printed
Page 262
Code fragment for ps1,ps2

Classes Ps1 and Ps2 are defined as inheriting from object, this is no longer necessary in Python 3 and should be removed.

Just declare them as

class Ps1:
... with remaining code ...

class Ps2:
... with remaining code ...

Paul McGuire
 
Dec 11, 2023 
Printed
Page 273
Code example beginning with "import heapq"

Class KeyHeap is defined as inheriting from object. This is a legacy from Python 2, no longer required in Python 3. The first line of the class declaration should be:

class KeyHeap:

Paul McGuire
 
Dec 11, 2023 
Printed
Page 284
Table of str methods

Omitted entries for str.partition and str.rpartition.

Consider merging all the is* methods and r* methods into consolidated entries to save table space.

Paul McGuire
 
Apr 25, 2024 
Printed
Page 289
Code example starting with ">>> name = 'Dawn'"

The second line of the example reads:

>>> print('{name} is {n} characters long'

In the following example output, Dawn is enclosed in single quotes. To get this, the example print statement should be:

>>> print('{name!r} is {n} characters long'

Paul McGuire
 
Dec 11, 2023 
Page 471
Code snippet on that page

The code on this page isn't safe to be called from multiple threads. For example, this code will occasionally detect errors where some results are returned "out of order".

def test_serializer():
"""Tests the Serializer class."""
serializer = Serializer()

def f(ii):
expected = ii*ii
actual = serializer.apply(lambda x: x * x, ii)
if actual != expected:
print(f"{expected=}, {actual=}")

for i in range(10):
threading.Thread(target=f, args=(i,)).start()

test_serializer()

The Serialiser is fine if there is only ever one calling thread, putting tasks on the queue for the other thread to execute. The race condition occurs when multiple threads are invoking apply() simultaneously, in which case it's possible for any given invocation to return the result from another thread's invocation.

Note from the Author or Editor:
I replicated the reported issue, the submitter is correct. Need to confer with co-authors to compose a suitable correction to this code example.

Update 13 Jan 2024 - after reviewing with co-authors, we have updated this code example to use type-safe data structures (view changes in the Github repository) - great catch, thanks!

Dave Slotnick  Nov 15, 2023 
Page 578
Code block, 4th last line

"cconcurrent.futures" instead of "concurrent.futures"

Note from the Author or Editor:
This is a typo in the source of the example code on this page.

with cconcurent.futures.ThreadPoolExecutor(20) as e:

Should be:

with concurent.futures.ThreadPoolExecutor(20) as e:

Tim Stamp  Sep 25, 2023 
Page 674 - What's new in Python 3.8
2nd line of table, after headers

The entry lists "Positional-only and named-only parameters (/ and * arg separators)". Only positional-only arguments (/ symbol in function signature) are new in Python 3.8 - see PEP-570. Keyword-only arguments (* symbol) were introduced back in Python 3.0 - see PEP-3102.

Note from the Author or Editor:
Thank you for submitting! The wording in the table should be changed to read "Positional-only '/' argument separators", since '*' argument separators were already supported as of Python 3.0. We'll also revisit the text on pp.95-97 to make sure that version markers are correctly placed.

Matt Morrison  May 01, 2023 
Printed
Page 681
entry for enum.StrEnum

enum.StrEnum was erroneously listed in the table of changes in Python 3.10, but this change was not actually made until Python 3.11. This entry should be moved to the table for Python 3.11 (approx. p. 684)

Affects all versions and translations of this book.

Paul McGuire
 
Nov 16, 2023