Errata

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
Page Back Cover
Last paragraph

"The book contains a foreword by Guido van Rossum, the creator of Python."
The book contains an Introduction to Chapter 13 by Guido van Rossum.

Anonymous   
Printed
Page 6
paragraph starting with "String objects..."

s.toupper()

NOW READS:
s.upper()

Anonymous    Aug 01, 2005
Printed
Page 18
1st paragraph,4 occurences

"anyset"

NOW READS:
"aset"

Anonymous    May 01, 2005
Printed
Page 34
code of expand_at_linestart()

mo.group().expand
should read:
mo.group().expandtabs

Anonymous    Jul 01, 2007
Printed
Page 43
2nd paragraph under Solution

...(i.e., diaeresis) character "ae".

NOW READS:
...(i.e., diaeresis) character "a-umlaut".

Anonymous    May 01, 2005
Printed
Page 67
4th line from the bottom of the page

"7 input_file = open(..."

NOW READS:
"input_file = open(..."

Anonymous    May 01, 2005
Printed
Page 73
Second code snippet

return mo.group(0)

NOW READS:
yield mo.group(0)

Anonymous    Aug 01, 2005
Printed
Page 75
code in the center of the page under Solution

To clarify the code sample, the line
record_number = 6

HAS BEEN ADDED, just after the line starting
record_size =...

Anonymous    May 01, 2005
Printed
Page 83
last line of page

Comment in sample code reads
# emits The average of 1 and 3 is 4
should read
# emits The average of 1 and 3 is 2

Anonymous    Jul 01, 2007
Printed
Page 173
third paragraph from the bottom

d.setdefault
should be:
d1.setdefault

Anonymous    Jul 01, 2007
Printed
Page 209
First paragraph

...if n, the number of items you need, is small compared to
n, the sequence's length. sort is very fast, but it still takes 0(n log n) time, while we
can get the first n smallest elements in time 0(n) if n is small.

should read:

...if n, the number of items you need, is small compared to
L, the sequence's length, sort is very fast, but it still takes 0(L log L) time, while we
can get the first n smallest elements in time 0(n) if n is small.

Anonymous    Jul 01, 2007
Printed
Page 241
First text paragraph

(See recipe 6.18...
should read:
(See recipe 6.7...

Anonymous    Jul 01, 2007
Printed
Page 246
Very last line

if key not in do_not_delegate:

NOW READS:
if key not in self.do_not_delegate:

Anonymous    Aug 01, 2005
Printed
Page 259
second line from the bottom

self.__class__ = __Full

NOW READS:
self.__class__ = self.__Full

Anonymous    Aug 01, 2005
Printed
Page 271
second line of code from the bottom

cls._inst = type.__new__(cls, *args, **kwargs)

NOW READS:
cls._inst = super(Singleton, cls).__new__(cls, *args, **kwargs)

Anonymous    Aug 01, 2005
Printed
Page 272
4th paragraph

The 'eggs' parameter passed when trying to instantiate s2...Singleton!

NOW READS:
The 'spam' parameter originally passed when s1 was instantiated has
now been trampled upon by the re-instantiation -- that's part of the
price you pay for having a Singleton!

Anonymous    Aug 01, 2005
Printed
Page 274
last 2 lines on page

def __new__(cls, *a, **k):
obj = object.__new__(cls, *a, **k)

NOW READ:

def __new__(cls, *a, **k):
obj = super(Borg, cls).__new__(cls, *a, **k)

Anonymous    Aug 01, 2005
Printed
Page 299
End of first paragraph

The typeface is incorrect in the last sentence; the fixed width face of 'cPickle' is
used for the remainder of the sentence.

Anonymous    Jul 01, 2007
Printed
Page 310
7.9 title

"7.9 Accesssing a MySQL Database"

NOW READS:
"7.9 Accessing a MySQL Database"

Anonymous    May 01, 2005
Printed
Page 330
Code section, LINE 6

excelfile, ", ")

NOW READS:
excel_file, ", ")

Anonymous    May 01, 2005
Printed
Page 338
penultimate line

...caused the probl7em...
should read:
...caused the problem...

Anonymous    Jul 01, 2007
Printed
Page 386
def makeNonBlocking() function

lines 1, 3 and 5: os.F_GETFL and os.F_SETFL were incorrect.

The code NOW READS:

fl = fcntl.fcntl(fd,fcntl.F_GETFL)
try:
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.O_NDELAY)
except AttributeError:
fcntl.fcntl(fd, fcntl.F_SETFL, fl | os.FNDELAY)

Anonymous    Aug 01, 2005
Printed
Page 403
in code

backup_dir = os.path.join(dir, bakdir_name)
if not os.path.exists(newdir):
os.makedirs(newdir)

NOW READS:

backup_dir = os.path.join(dir, bakdir_name)
if not os.path.exists(backup_dir):
os.makedirs(backup_dir)

Anonymous    May 01, 2005
Printed
Page 404
code at top of page

After the line:

old_backup = '%s.%2.2d' % (destpath, index-1)

the line:

abspath = os.path.abspath(filepath)

HAS BEEN ADDED.

Anonymous    Aug 01, 2005
Printed
Page 444
code listing, 6th line from bottom

The line
dom = parseString(data)
should be
dom = parseString(example_data)

Anonymous    Jul 01, 2007
Printed
Page 472
Recipe 12.5 code: class Xml2Obj, func EndElement

In this code:

def EndElement(self, name):
'Expat end element event handler'
self.nodeStack[-1].pop( )

the last line is wrong. It should read:

self.nodeStack.pop( )

Anonymous    Jul 01, 2007
Printed
Page 472
Code, Line 23

The printed code misses a colon:
class Xml2Obj(object)
should be:
class Xml2Obj(object):

Anonymous    Jul 01, 2007
Printed
Page 504
line 16 of the source code

The source in the book and in the samples zip file is:
rx_headers = re.compile('|'.join(headers), re.IGNORECASE)

but it should be to work properly (it's case sensitive):
rx_headers = re.compile('|'.join(HEADERS), re.IGNORECASE)

Anonymous    Jul 01, 2007
Printed
Page 563
2nd code block, 5th line

Text says:
#emits: I an a con

Should be:
#emits: I am a con

Anonymous    Jul 01, 2007
Printed
Page 594
3rd line of code on page

return f(*(a+more_a), dict(kw, **more_kw))

NOW READS:
return f(*(a+more_a), **dict(kw, **more_kw))

Anonymous    May 01, 2005
Printed
Page 596
4th line of code on page

return f(*(more_a+a), dict(kw, **more_kw))

NOW READS:
return f(*(more_a+a), **dict(kw, **more_kw))

Anonymous    May 01, 2005
Printed
Page 599
code snippet

for token in tokenize.generate_tokens(text.readline):
^^^^^
# unpack ...
toktype, toktext, ... = token (*)
^^^^^

This variable token collides module "token".

AUTHOR:
The simple fix is just to rename this variable to anything else
(such as 'tok') in both the for statement and the assignment statement
(there are no other uses of this variable; following occurrences of
identifier 'token' refer to the module of that name).

Anonymous   
Printed
Page 605
last paragraph (also on next page at see also)

Site that is referred to does not exist any more; new site is at
http://www.dabeaz.com/ply/

Anonymous    Jul 01, 2007
Printed
Page 743
6th line of code on page

f.func_defaults = deepcopy(fdefaults)
should be:
f.func_defaults = copy.deepcopy(fdefaults)

Anonymous    Jul 01, 2007
Printed
Page 774
4th line of code in this page

obj = super(MetaAuto, cls).__call__(cls, *a, **k)
should be changed to
obj = super(MetaAuto, cls).__call__()

AUTHOR'S REPLY:

The reader's observation is ALMOST correct; the proper expression is
neither the one in the book, nor the one he suggests, but rather the
following one:

obj = super(MetaAuto, cls).__call__(*a, **k)

To check this, the reader can run, for example, the following code
(together with what he can find in cb2_20_14_exm_3.py in the zipfile
of all code in the book, available at http://examples.oreilly.com/
9780596007973/cb2_examples.zip ):

class named_recorder(auto_object):
count = 0
events = attr(list)
def __init__(self, name):
self.name = name
def __str__(self):
return '%s: [%s] %s' % (self.name, self.count, self.events)
def record(self, event):
self.count += 1
self.events.append((self.count, event))

r1 = named_recorder('uno')
r2 = named_recorder('dos')
r1.record('zap')
r2.record('zop')
print r1
print r2

This code raises exceptions with both the original formulation (which
wrongly repeats cls) and his suggested one (which wrongly omits *a,
**k), but works as intended with the proper formulation (without
repetition of cls, but WITH *a,**k) given above.

Anonymous    Jul 01, 2007
Printed
Page 798
Microsoft index entries

Not really a mistake, just an index inconsistency for similar items with more than
one name:

For Microsoft Access, there is the index entry:
"Microsoft Access (see Access)"
and the "Access" entry has the page details.

Alternatively:
The "Microsoft Excel" entry has the page details,
and the "Excel (See Microsoft Excel)" refers to it.

Another alternative:
The "Microsoft Outlook" entry has the page details,
and so does the "Outlook" entry.

Yet another alternative, the three entries:
"Microsoft {Jet,ODBC standard,SQL Server}" have the page details but no corresponding
entry without the Microsoft prefix.

Anonymous   
Printed
Page 805
Twisted Index entry

The index entry for "Twisted" references only page 356, but the word "Twisted" does
not appear on page 356. It is instead the first word on Page 357. There are also
references to Twisted on pages 486, 508-511, and 519-524 that are not in the index.

Anonymous