Errata for Python in a Nutshell

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.

The Meaning of the -tt option reads:
"Like -tt, but raises an error rather than a warning"
now reads:
"Like -t, but raises an error rather than a warning"
p. 45 --
"from future import division"
now reads:
"from __future__ import division"

Anonymous

Sep 01, 2003

Printed

Page 47
Pargraph "Slicing a sequence", lines 4-5

"j is less than i"
now reads:
"j is less than or equal to i"

Anonymous

Sep 01, 2003

Printed

Page 48
Modifying a list, 2nd bulleted item

L[i:i]=['a','b'] inserts the items 'a' and 'b' after item i in L.
now reads:
L[i:i]=['a','b'] inserts the items 'a' and 'b' before item i in L.

Anonymous

Sep 01, 2003

Printed

Page 48
Last paragraph

The last sentence ends with
"..., while L*=n has the effect of adding n copies of L to the end of L."
The last sentence now reads:
"..., while L *= n has the effect of adding n-1 copies of L to the end of L."

Missing "to" in "A bound method is similar TO an unbound method,..." has now been added.

Anonymous

Sep 01, 2003

Printed

Page 85 & 86
code examples

The code samples use the variable "heigth", which is now correctly spelled as "height".

Anonymous

Sep 01, 2003

Printed

Page 86
middle of the page

The code:
class OptimizedRectangle(object):
__slots__ = 'width', 'height'
__slots__ cannot usefully be added by inheritance in this way; so the
example should be rewritten to avoid inheritance and rather just copy
the whole Rectangle class as given at the top of page 85 under the new
name OptimizedRectangle:
class OptimizedRectangle(object):
__slots__ = 'width', 'height'
def __init__(self, width, height):
self.width = width
self.height = height
def getArea(self):
return self.width * self.height
area = property(getArea, doc="area of the rectangle")

Anonymous

Printed

Page 100
IN PRINT: Single line of code near bottom of page

"__metaclass_ = type"
Now reads:
"__metaclass__ = type"

Anonymous

Sep 01, 2003

Printed

Page 100
Last sentence, 5th paragraph

"Since type(object) is type, a class C that inherits from object (or some other built-
in type) gets the same metaclass as object (i.e., type(C), C's metaclass, is also
type) Thus, being a new-style class is synonymous with having type as the metaclass."
"Thus, being..." is the start of a second sentence. A period HAS BEEN ADDED to the end of the sentence
"Since type(object)...".

where it says:
For more on buffer, see Chapter 13.
The text now reads:
The buffer built-in is now deprecated.

Anonymous

Sep 01, 2003

Printed

Page 163
IN PRINT: Code listing near top of page, third line

"if re.search(..."
Now reads:
"if digatend.search(..."

Anonymous

Sep 01, 2003

Printed

Page 163
Bottom

The bottom line of text was missing in printings after 9/03.
the missing line was:
want to print only words that are followed by whitespace (not
THIS HAS BEEN CORRECTED.

Anonymous

Aug 01, 2005

Printed

Page 164
Description of "map - last paragraph

The last Paragraph of the description of map states:-
"When func is None, map returns a list of tuples ..."
This is only true if map is given at least 2 seqs to "map".
If it is given a single seq, it returns the seq itself.
This can cause serious errors in programs that expect
tuples to be returned.

Note from the Author or Editor:p. 164 under `map`, 2nd paragraph, change the text that now reads
When func is None, map returns a list of tuples, each with n items (one item from each iterable); this is
to read
When func is None, map returns a list of tuples, each with n items (one item from each iterable) when n>1; this is
and add to the same paragraph (which now ends "the longer ones.") a further sentence
When func is None and n is 1, map returns a list of the items of seq (while zip would return a list of tuples with just one item each).

Ross Cartlidge

Jan 29, 2009

Printed

Page 177
Last paragraph

The os.path Module functions table is missing the "expanduser" method
and related description. (See, for example, the documentation at the
following URL: http://python.org/doc/2.2.3/lib/module-os.path.html)

"but calling lstat on a file that does not support seeking ..."
should be:
"but calling lseek on a file that does not support seeking ..."

Anonymous

Printed

Page 202
Example code, data_to_zip_direct

To make the example work the same way for both the direct and indirect method, the line:
zinfo.compress_type = zipfile.ZIP_DEFLATED
HAS BEEN ADDED after the line:
zinfo = zipfile.ZipInfo(name, time.localtime()[:6])

When languages is None, translation looks in the environment for the lang to use, like install.
However, languages can also be a list of one or more lang names separated by colons (:), in which
case translation uses the first of these names for which it finds a .mo file.
NOW READS:
When languages is None, translation looks in the environment for the lang to use, like
install: it examines, in order, environment variables LANGUAGE, LC_ALL, LC_MESSAGES, LANG -- the first
non-empty one is split on ':' to give a list of lang names (for example, 'de:en' would be split to give ['de','en']).
When not None, languages must be a list of one or more lang names (for example, ['de','en']). Translation uses the
first lang name in the list for which it finds an .mo file.

"in releases of Python older than the ones covered in this book,
unpickling from an untrusted data source was a security risk ... No
such weaknesses are known in Python 2.1 and later."
This is no longer true, the 2nd edition says:
Note that unpickling from an untrusted data source is a security risk; an attacker could
exploit this to execute arbitrary code. Don't unpickle untrusted data!

import os
os.spawnv(os.p_WAIT, editor, [textfile])
NOW READS:
import os
os.spawnv(os.p_WAIT, editor, [editor, textfile])
and, the last sentence NOW READS:
The first item of the argument <replaceable>args</replaceable> is
passed to the program being spawned as "the name under which the
program is being invoked". Most programs don't look at this, so you
can place any string there. Just in case the editor program does look
at this special first argument, passing the same string
<replaceable>editor</replaceable> that is used as the second argument
to os.spawnv is the simplest and most effective approach.

Anonymous

Aug 01, 2005

Printed

Page 303
5th paragraph, tofile

tofile Note that f should be open for reading in binary mode, for example with
mode 'rb'.
now reads:
tofile Note that f should be open for writing in binary mode, for example with
mode 'wb'.

Anonymous

Sep 01, 2003

Printed

Page 307
Code listing, under Slicing Examples

a[0,2:4)
Now reads:
a[0,2:4]

Anonymous

Sep 01, 2003

Printed

Page 312
5th paragraph

where it says:
an array with rank of one less than a and of the same size as a
The text now reads:
an array with rank 1 and of the same size as a

Anonymous

Sep 01, 2003

Printed

Page 320
3rd paragraph

where it says:
just like array(a,copy=False).flat
The text now reads:
just like array(a,copy=(not a.iscontiguous())).flat

Anonymous

Sep 01, 2003

Printed

Page 328
the URL

http://starbase.neosoft.com/~claird/comp.lang.python/python_GUI.html
The URL has changed and now reads:
http://phaseit.net/claird/comp.lang.python/python_GUI.html

Anonymous

Sep 01, 2003

Printed

Page 335
5th paragraph

In the example to diplay GIF images in the example, the line:
img.config(image=gifsdict[imgname])
Is now indented as follows:
def list_entry_clicked(*ignore):
imgname = L.get(L.curselection()[0])
img.config(image=gifsdict[imgname])

Anonymous

Sep 01, 2003

Printed

Page 337
2nd paragraph of Entry section

An Entry instance with state=DISABLED is a good way...
"state=DISABLED" should be replaced by "state='readonly'" for the
remainder of the page.
state=DISABLED doesn't allow you to select an Entry's text
or copy it to the clipboard.

Note from the Author or Editor:p. 416 and 417 *NOT* 337, change all occurrences of DISABLED (I count four) to 'readonly' (lowercase and with single quotes around). So for example
state=DISABLED
must become
state='readonly'
and so on.

Anonymous

Printed

Page 337
last table entry

toggle c.deselect()
Now reads:
toggle c.toggle()

Anonymous

Sep 01, 2003

Printed

Page 342
middle of page

The entry for 'iconify' shows 'deiconify' for the example.
Iconify T.deiconify()
Now reads:
Iconify T.iconify()

Anonymous

Sep 01, 2003

Printed

Page 346
Under "Menu Example" heading

The following two lines have been added to the end of the script:
root.config(menu=bar)
Tkinter.mainloop()

Anonymous

Sep 01, 2003

Printed

Page 346
code sample at very bottom

def makeshow(menu):
def emit(entry, menu=menu): print menu, entry
return emit
NOW READS:
def mkshow(menu, entry):
def emit(): print menu, entry
return emit
AND the first two lines on the top of page 347;
and use command=mkshow('File') and command=mkshow('Edit'),
respectively, in the calls to the add_command methods of fil and edi.
NOW READ:
and use command=mkshow('File', x) and command=mkshow('Edit', x),
respectively, in the calls to the add_command methods of fil and edi.

omitted nlist method.
The nlst method should probably be included, in its normal alphabetical order
(i.e., after mkd but before pwd) with the text (in the usual mixture of fonts
and typefaces like for the other methods):
nlst f.nlst(pathname='.')
Sends a NLST command to the FTP server, asking for the names
of the files in the directory named by pathname (by default,
the current directory), and returns the list of the filenames.
((i.e., as usual, I would omit weird, rarely used stuff such as, in this case,
the optional, non-portable extra arguments)).

where it says
ntohl htonl(i32)
The text now reads:
ntohl ntohl(i32)
AND
where it says
ntohs htons(i32)
The text now reads:
ntohs ntohs(i32)

Anonymous

Sep 01, 2003

Printed

Page 441
Example code at bottom of page

The example trivial HTTP server is missing the two lines to instantiate and start up the server.
After the line do_HEAD = do_POST = do_GET, the following two lines have been added:
server = BaseHTTPServer.HTTPServer(('',80), TrivialHTTPRequestHandler)
server.serve_forever()

Anonymous

Sep 01, 2003

Printed

Page 445
example 19-6; the final lines of code (at the end of the "for x in i: portion of the example")

quoteattr escape(data,entities={})
Now reads:
quoteattr quoteattr(data,entities={})
Pages 507, 508, and 511:
The following warning note has been added on page 511:
The code examples given on pages 507, 508 and 511 may crash under
some version of Python and Windows (not Python 2.3, and not Linux
versions of Python). To fix your version of Python so that it is able to
run the examples, visit URL:
http://sourceforge.net/project/showfiles.php?group_id=6473
and download and run the appropriate self-installing .EXE, for example
currently PyXML-0.8.2.win32-py2.2.exe if you run Python 2.2 on any
version of Microsoft Windows. This self-installing EXE will add to your
Python installation the latest version of the "XML subsystem" of Python,
and, as a side effect, fix any bugs connected to XML handling that may
have been diagnosed after the release of your version of Python.

Anonymous

Sep 01, 2003

Printed

Page 536
Example 24-1

There are two arrays declared as
static char merge_docs[]
The second one (page 536) now reads:
static char mergenew_docs[] = "

Anonymous

Sep 01, 2003

Printed

Page 567
Manifest section 1st bullet

sdist default does not include scripts or data files, even if specifically mentioned
in the setup.py script. The default only includes:
"all Python source files implied by the py_modules and packages options"
To include scripts or data files by sdist, you have to create a MANIFEST.in

Anonymous

Printed

Page 569
Bottom paragraph

The Installer website NOW READS:
http://www.mcmillan-inc.com/install1.html

There is no entry in the index for the consept "frozen", mentioned on page 121 just
before and after the heading "Searching the Filesystem for a Module".
Worse IMHO, there's no explanation in the book, that I can find, on what "frozen
modules" is. A line or two on page 121 would have been nice.

Anonymous

Sign up today to receive special discounts, product alerts, and news from O'Reilly.