Python Cookbook

Errata for Python Cookbook

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
Page 3
code example of 2nd paragraph under Solution section

>>> record = ('Dave', 'dave@example.com', '773-555-1212', '847-555-1212') >>> name, email, *phone_numbers = user_record should read: >>> user_record = ('Dave', 'dave@example.com', '773-555-1212', '847-555-1212') >>> name, email, *phone_numbers = user_record or: >>> record = ('Dave', 'dave@example.com', '773-555-1212', '847-555-1212') >>> name, email, *phone_numbers = record

Note from the Author or Editor:
Change line in middle of change to: >>> name, email, *phone_numbers = record

Mingway Huang  Oct 07, 2013  Mar 07, 2014
Printed
Page 19
last example at botom of page

This example "a.indices(len(s))" leads to output that differs from the output as printed in the book, assuming the slice a is the slice a as shown in the example just above. It would work in the way shown, if a were slice(5, 50, 2) or so. Or am I wrong?

Note from the Author or Editor:
Change example mid-page to this: >>> a = slice(5, 50, 2) >>> a.start 5 >>> a.stop 50 >>> a.step 2 >>> Problematic example at bottom should then work.

Oli  Sep 27, 2013  Mar 07, 2014
PDF
Page 23
Second line of first in-line example.

The line rows_by_lfname = sorted(rows, key=lambda r: (r['lname','fname'])) gets an exception : KeyError: ('lname', 'fname'). I believe that it should read rows_by_lfname = sorted(rows, key=lambda r: (r['lname'], r['fname']))

Note from the Author or Editor:
Fixed in final book.

Colin McPhail  May 04, 2013  May 08, 2013
Printed
Page 28
In the "addresses" list of the example on the top half of the page.

There is a comma missing following '2122 N CLARK' in the addresses list . As a result the output is incorrect.

Doug Hill  Dec 12, 2013  Mar 07, 2014
PDF
Page 39
2nd example

missing "]" at the end of line

Note from the Author or Editor:
4th line from bottom of 2nd example needs to read ['foo.c', 'spam.c', 'spam.h' ]

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 57
middle of page

Text says " All of these methods accept an optional &&65.180&&fill character as well. For example:" Not sure what the &&65.180&& means? Or should be instead?

Note from the Author or Editor:
Typographical problem. Should just read "optional fill character"

None  Aug 12, 2013  Mar 07, 2014
PDF
Page 67
1st example

Missing ' in ('NUM', 10')

Note from the Author or Editor:
Should read ('NUM', '10') End of 2nd line in code sample at top of page.

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 71
middle of the page

"on on" repeated words in ExpressionEvaluator class docstring

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 111
middle of the page

The 2013 U.S. standard daylight saving time started in March 10, not March 13 as stated on the paragraph. The examples are correct, showing day 10.

Note from the Author or Editor:
Yes, March 10.

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
Printed
Page 135
Item 4.14

I think that the recursive call should be yield from flatten(x, ignore_types) not yield from flatten(x)

Note from the Author or Editor:
Yes.

Anonymous  Sep 18, 2013  Mar 07, 2014
Printed
Page 138
Second code example

process_data(data) should be process_data(chunk) *or* for chunk in iter( should be for data in iter(

Note from the Author or Editor:
use: process_data(chunk)

Andy H  Feb 12, 2014  Mar 07, 2014
Printed
Page 144
5.2 printing to a file

wrong: with open('somefile.txt', 'rt') as f: print('hello world', file=f) correct: with open('somefile.txt', 'wt') as f: print('hello world', file=f)

Michael Poeltl  Sep 29, 2013  Mar 07, 2014
PDF
Page 165
last paragraph

There's an extra ) at the end of the last paragraph: However, if you are writing a script that actually needs to dump binary data to standard output, you can use the technique shown to bypass the text encoding.)

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 172
2nd example

There's an extra period at the end of: import pickle.

Note from the Author or Editor:
Get rid of the period. >>> import pickle

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 180
page bottom

Missing comma after } at the end of 4th-to-last line: },

Note from the Author or Editor:
Yes. }, { 'created_at': ... }

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 202
second code snippet

In the definition of read_records, the return statement is redundent and technically wrong since the function intends to return a generator.

Note from the Author or Editor:
Delete "return records" statement in the last line of the code sample in bottom half of page.

Binshuo Hu  Jan 05, 2014  Mar 07, 2014
PDF
Page 246
2nd example

def __init__(self, address, family=AF_INET, type=SOCK_STREAM): self.address = address self.family = AF_INET self.type = SOCK_STREAM Should be: def __init__(self, address, family=AF_INET, type=SOCK_STREAM): self.address = address self.family = family self.type = type To really use the "family" and "type" arguments, if informed.

Note from the Author or Editor:
Yes: self.family = family self.type = type

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 253
code, last line

Incorrect: name = property(get_first_name, set_first_name, del_first_name) Correct: first_name = property(get_first_name, set_first_name, del_first_name)

Note from the Author or Editor:
Yes, 'name =', needs to be 'first_name = '

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 262
last code

Incorrect: @Person.getter Correct: @Person.name.getter

Note from the Author or Editor:
Change @Person.getter to @Person.name.getter

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
Printed
Page 284
10th line

The line reading: self._items = sorted(initial) if initial is None else [] misses a not. It has to be: self._items = sorted(initial) if initial is not None else [] (This mistake is also present in the example1.py of this chapter)

Kirchmann,Gerhard  Jun 24, 2013  Mar 07, 2014
Printed
Page 285
32nd line

The line reading: self._items = list(initial) if initial is None else [] misses a not. It has to be: self._items = list(initial) if initial is not None else [] (This error is also present in example2.py of this chapter)

Note from the Author or Editor:
Yes. self._items = list(initial) if initial is not None else []

Kirchmann,Gerhard  Jun 24, 2013  Mar 07, 2014
PDF
Page 293
Last paragraph, second to last line

On page 293, last paragraph, second to last line the sentence 'By using setattr() to set the values...' breaks the 'setattr()' awkwardly, putting the 'se' on one line and 'tattr()' on the next line.

Note from the Author or Editor:
Still in print edition.

Nick Stevens  Mar 11, 2013  Mar 07, 2014
PDF
Page 311
code

"import types" is repeated in the code.

Note from the Author or Editor:
Yes, the second 'import types' that appear right before 'class NodeVisitor:' can be deleted.

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 580
middle of the page

Incorrect: ... raise RuntimeError('A parsing error occurred') from e... Correct: ... raise RuntimeError('A parsing error occurred') from e ... (the ... prompt got joined to the previous line)

Note from the Author or Editor:
Not in printed copy, but the '...' needs to be on its own line as described.

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 581
last example

Incorrect: ... raise RuntimeError('A parsing error occurred') from None... Correct: ... raise RuntimeError('A parsing error occurred') from None ... (the ... prompt got joined to the previous line)

Note from the Author or Editor:
Not seeing this in the printed copy, but yes, the '...' needs to be on its own line if it's not.

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 594
1st paragraph in topic Discussion

Repeated words in the sentence: "the implementation of an an O(n**2) algorithm."

Note from the Author or Editor:
Remove the second "an".

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014
PDF
Page 597
code, first line

Garbage after comment in the first line of the C code. Incorrect: /* sample.c */_method Correct: /* sample.c */

Note from the Author or Editor:
Delete the "_method" after the comment.

Aurelio Jargas  Nov 12, 2013  Mar 07, 2014