PDF Versions (short versions do not have minor errata):
There will inevitably be errors when writing a book no matter how
hard we try to keep it clean. In other words, "Don't (necessarily)
believe everything you read!" A lot of hands touch the text before
the book finally ends up in your hands, so here is where we try to
clean it up. Even some of my own corrections found in the draft
were not implemented due to lack of time or priority during the
highly-compressed editing phase.
With regards to the corrections to the source code for the Examples
in the book, MINOR problems do not prevent
the script from running, but CRITICAL bugs
means that the code printed as-is will not execute. We will provide
changes or differences ("diffs") whenever possible. The diffs
between the files are
If you find a new problem, send it to us at
Page(s) :: Section (may also
have Figure, Table, or Example number) :: Subsection (if appl.)
: correction
Text which is in red indicates a change.
xxxiv :: Preface : Book Resources :
In the second sentence, add a comma between "errata"
and "source code".
11 :: 1.4 :: Build It Yourself :
The third step,
17 :: 1.5.2 :: Unix :
In the final paragraph of this section, we should also point
out that executing
21 :: 1.5.4 :: Open Source :
We inadvertently left out another popular IDE called
Stani's Python Editor (SPE). The link to it:
http://pythonide.stani.be/
43 :: 2.12 :
The sequence in the first
52 :: 2.18 : How to Create Class Instances :
In the (first [John Doe]) sample output for calling
Even more importantly, our goal for keeping the text file
platform-independent was defeated by the
The fix is to change the Python line terminator back to a
solitary NEWLINE on line 30 and let the C library "do the right
thing" for its respective platform. We apologize for any confusion
caused for readers new to Python or cross-platform issues.
Our original fix looked like this:
However, rather than process lines by adding a
NEWLINE to each and sending the resulting list out to disk
with the
85 :: 3.8 : Exercises 3-7 :
The spacing gap between the 1st row of potential identifiers is greater
than for the remaining rows. It should be reduced to match the rest.
104 :: 4.6.3 : Core Note :
It is likely that the back ticks (
116 :: 4.9 ::
NEW -- Thanks to Greg Nofi (May 07) and Mark Ackerman (Jan 08)
173 :: 6.3.2 : Example 6.1 :
Line 1 is missing the (root directory) first forward slash in the *ix
start-up directive; it should be,
188-190 :: 6.22 : Table 6.6 :
The
189-190 :: 6.22 : Table 6.6 :
The
190 :: 6.22 : Table 6.6 :
The
190 :: 6.22 : Table 6.6 :
The signature for
199 :: 6.8.3 :
The last few sentences of the first complete paragraph on this page
are erroneous now. The
219 :: 6.13.2 ::
240 :: 6.19 :
Fix this typo in the final paragraph of this section at the top
of the page: "... also contains the same for sequence types." (This refers to
the functional equivalents to sequence type operators.) Also,
the final three sentences (with the first beginning with,
"Finally,...") SHOULD BE REMOVED as Python now does
support subclassing of the standard types.
247-248 :: 6.22 :: Exercise 6-7 and "Example 6.4" :
250 :: 6.22 :: Exercise 6-18 :
The subtitle of this problem should read, "
267 :: 7.4 :
In the first sentence of the second paragraph (right below the code
snippet), "directory" is the wrong word and should be changed: "...
add the contents of one dictionary to another."
NEW (May 08)
303 :: 8.6.5 :
There is a misspelling of "returning" in the final sentence of
this paragraph. Also, so readers don't have to hunt for the
reference, the final sentence should end with, "... similar to
views as discussed in the previous chapter at
the end of Section 7.4."
384 :: 10.4.2 :: Context Expression, Context Manager :
Italicize
387-389 :: 10.6.1 including Table 10.1 :
Italicize all the variables, such as
and
386, 394 :: 10.5, 10.8 :
In the final paragraph for section 10.5, we describe the
obsolescence of string exceptions. The raising exceptions in
Python 2.5 resulting in a warning can be further clarified that
it will no longer be allowed in 2.6. Similarly, the catching of
string exceptions results in a warning beginning in 2.6 but will
not be allowed in 2.7.
390 :: 10.7.1 :
With regards to the
391-393 :: 10.8 : Table 10.2 :
Various editing errors exist in the table of standard exceptions:
395-397 :: 10.9 :: Example 10.2 :
414 :: 11.2.4 :: Example :
In the 2nd paragraph, remove the space in "binary operators/ operations".
NEW -- Thanks to Tony Tang (May 08)
443 :: 11.7.2 :: Figure 11-1 :
The "0" and "1"s inside the box representing the boolean function
444 :: 11.7.2 ::
465 :: 11.8.5 :
Just before the middle of the page, in the final definition of
469 :: 11.10.1 :
In the code snippet in the middle of the page, we should have
used
Finally, all three of the code snippets used in this subsection can now
be downloaded here (as of Dec 6).
474 :: 11.11 :: Exercise 11-13 :
Reword part (c) to: Discard
488 :: 12.5.4 :
The final sentence of the second paragraph features a misspelling
of
494 :: 12.7.1 :
Towards the end of this section, the reference to
495 :: 12.7.4 :
At the bottom of the page when importing
502 :: 12.10 : Exercise 12-6 :
Resolving various spacing issues in the example call, we get:
515 :: 13.2.1 :
The 2nd to last sentence in this section should end with "OOD"
instead of "OOP", otherwise it reads like infinite recursion,
or "Mr. Bunny's Guide To Java".
520 :: 13.4.1 :
Since this section is optional (as per the previous section),
there should be a "*" in front of the subsection title.
524 :: 13.4.4 :
Under Table 13.1, the first paragraph should start with the
following: "In addition to the
543 :: 13.8.1 :
In the
553 :: 13.11.3 :
In the
586 :: 13.14 :: Single Underscore ( _ ) :
Remove the "we" in the 2nd half of the final sentence on this page.
603 :: 13.16.4 :: Descriptor Examples :
In the middle of the page, the sentence that starts with,
"Our final example...," should refer to Example 13.9 on the
next page. Otherwise, you may think that it refers to the
previous code snippet.
604 :: 13.16.4 :: Example 13.9 :
607 :: 13.16.4 : Properties and
609 :: 13.16.4 : Properties and
You can download this code here. The output of
executing the code above will look like this:
In the final paragraph on this page, keep only the first
sentence, beginning with, "Our code works exactly as before...."
Drop the final 2 sentences.
622 :: 13.18 :: Exercise 13-9 :
The descriptions of the
625 :: 13.18 :: Exercise 13-20 :
The font for the first and last lines of code in part (f) are oversized
and should be shrunk to match the remaining lines of code. Also, add a
part (g) which reads, "(g) Can we move the math-oriented code out of
644-645 :: 14.3.6 :: Creating Code at Runtime and Executing It :
For those unfamiliar with the C shell and its descendants, you can
change the
652 :: 14.4.1 :
In the final paragraph
657 :: 14.5.2 :
In the (sub)section title
661 :: 14.5.5 :
The reference to
664 :: 14.7.1 :: Example "14.4" :
Globally replace "14.4" with "14.3" ... there is no Example 14.4.
UPDATED (May 08)
669 :: 14.10 :: Exercise 14-9 (14-11) :: Extra Credit 2 :
The "
740 :: 16.5.2 :
In the 2nd paragraph, remove the hyphen from the call to
742 :: 16.6 :
Replace the final part of the final sentence with,
"... we strongly encourage you to read
ahead to Chapters 17 and 20."
NEW (May 07)
745 :: 16.7 :: Exercise 16-14 :
In the final portion of the exercise, change "i.e." to "e.g.".
754 :: 17.2.6 : Example 17.1 : Line-by-Line Explanation :
Lines 11-44 :
758 :: 17.3.4 : Table 17.2 :
In the entry for "xhdr", move the "[" back two characters, to,
762 :: 17.3.6 : Example 17.2 : Line 60 :
Not really a correction but a note that Generator Expressions
were added in Python 2.4, so if you are using 2.0-2.3.x, you
will need to switch it to a List Comprehension by changing the
parentheses to square brackets.
772 :: 17.4.8 : Figure 17-3 :
The not-well-arranged text on the second MUA down on the left
should read, "IMAP4/POP3 (receive)", similar to the one for
the bottom MUA as well as the one on the far right.
784 :: 17.6 : Exercise 17-28(a) :
Not really a correction, but add a... "Hint: see the
802 :: 18.5 : Table 18.3 :
There shouldn't be any spaces around the
868-869 :: 20.2.4 :: Line-by-Line Explanation :: Lines 24-29 :
Change the filename to
871 :: 20.3 :: Example 20.2 :
The code for the
879 :: 20.5.1 :
In the final paragraph of this section (above the URL links),
880, 890-892, 897-898 :: 20.5.2, 20.5.5, 20.7.4 : Figures
20-4, 20-9, 20-10, 20-11, 20-14, 20-15 :
The captions should be centered so they fit on a single line below
each figure.
911 :: 20.9 :: Table 20.7 :
In the description for the
913 :: 20.10 :: Exercise 20-3 :
Remove the extra comma in the reference to Example 11.4.
914 :: 20.10 : Exercises 20-10 and 20-11 :
Exercises 20-7 through 20-10 are related and grouped together;
there should be an extra blank line separating Exercise 20-10
and 20-11.
929 :: 21.2.3 :: Table 21.6 :
For the
939-945 :: 21.2.7 :: (Example 21.1) :
There is no output for Example 21.1; however, we do provide the
output of the equivalent ORM versions (twice) later in the
chapter. The output of those applications will be the virtually
the same, given the natural variations of the random numbers generated.
940-953 :: 21.2.7-21.3.3 :: Examples 21.1-21.3 :
In various places, the font was shrunk so as to not wrap lines.
This may look strange in the text. These include the following:
953 :: 21.3.3 :: Line-by-Line Explanation :
In the section for lines 79-80, there should not be a space
between the function name and parameters in the
NEW -- Thanks to Raven Erebus (May 08)
-u context diffs for those
of you who know what they are. Because there is no other source for
getting the code, all of the scripts for download
have already been corrected.
corepython (at)
yahoo.com. Each errata item follows the format below...
submit yours using the same format so that we can upload it faster to
this page. We are also interested in hearing comments, suggestions,
and general feedback, both good and bad. We want to continue
improving the book for future readers and editions! MANY THANKS!!
Text which is in gray indicates an erratum that
is of lower priority that is not normally displayed. Use the Toggle button below to swap between showing and hiding all minor errata.
Normal priority errata denoted NEW
or UPDATED
were added/changed between Feb 2008 and May 2008 (even if we were notified earlier than those dates) along with appropriate credit(s)
as necessary. We do not designate minor errata this way.
Text
FrontMatter
xxx :: Preface : Chapter Guide : Chapter 8 :
In the first sentence, for, while,
and if should be in Courier Bold
font, as all keywords are.
Chapter 1
1-2 :: 1 :
The book is misnumbered... page "1" is missing. The final page
of the Preface is xxxvii and jumps immediately to page 2 of the main
body of text.
make install will install the Python
you just compiled and set it as the default Python interpreter.
Should you wish to install multiple versions of the interpreter
or do not wish to replace the existing version, use make
altinstall. For example, if you have an existing Python
2.4.3 installtion then build and install 2.5 with make
altinstall, calling python from the
command-line still launches the 2.4.3 interpreter whereas to
start 2.5, you would need to use python2.5.
$ script.py directly from the
command-line only works if the current directory is part of
your PATH environment variable. If it is not,
you have to use ./ in front of the script name so
that it can be found, e.g., $ ./script.py.
Chapter 2
33 :: 2.1 :: Core Note :
In the final part of this sidebar, when dumping the previous
expression using the underscore, the output should be in quotes:
'Hello World!' (since the
string itself is the expression and not its contents).
int() to raise an error because it cannot convert
the input into a valid Python integer."
-- to the unary negation sign
- (single hyphen instead of two).
decimal.Decimal(), we mention that "[you] must import
the decimal module to use these types of numbers," but
we didn't do so at the top of p. 39, so add the following at the top:
>>> import decimal.
print statement at the top of
the page, there should be a space to separate "at" and "least".
for loop should not wrap.
This script prompts the user for a filename, opens the file, and
loops over the (text) file and displays one line at a time, and
finally closes the file. This technique or idiom is simple to
understand and works great, especially with large files because you
do not need the entire file in memory at the same time. As an
alternative for shorter files, take a look at this similar piece
of code:
filename = raw_input('Enter file name: ')
fobj = open(filename, 'r')
data = fobj.readlines()
fobj.close()
for eachLine in data:
print eachLine,
foo1.showname(), the output should not have
"__main__." in it. In other words, it should just be:
>>> foo1.showname()
Your name is John Doe
My name is FooClass
Chapter 3
as and assert
should be in Courier Bold, like they are in
the equivalent table in Appendix A on p. 1022.
makeTextFile.py
The code for line 10 is missing. It should be fname = raw_input('Enter file name: ')
and indented one level (at the same level as the line below it).
fopen()
C library call on Win32 platforms. For each NEWLINE (\n
or ASCII value 10) character encountered, it is replaced by the
two Win32 line terminators RETURN (\r OR ASCII 13)
and NEWLINE. This means that the original program created text
files with \r\r\n between lines, a minor text file
corruption and not our original intention.
fobj.writelines(['%s\n' % x for x in all])writelines() method, we preferred
merging all of the text lines into a single string delimited
by NEWLINE characters and performing a single
write():fobj.write('\n'.join(all))
(major
patch
[diff])Courier.
Now that we have the entire contents in memory, we need to dump
it to the text file. Line 29 opens the file for write, and line
30 writes each line to the file. Every file requires a line
terminator (or termination character[s]). The
'\n'.join(all)
takes each line of all (list of input strings), and
join()s them together into one large string delimited
by the NEWLINE character. That single string is then written out
to disk with the file object's write() method.
Chapter 4
range(-1, 100). As of Python 2.5, that has been
expanded to range(-5, 257).
obj in the "Function" column
should be in italics.
` `) will be deprecated
in a future version of Python (say 3.0).
class Foo definition should
say that is is a classic class definition (not a new-style class).
isinstance() is missing from the built-in functions
section of this table. The two possible syntaxes are:
isinstance(obj, cls) and
isinstance(obj, (cls1, cls2,... clsN)).
The description should read, "Determines whether an object is of a certain
type or class of types." Finally, it returns a bool. Also, the
description for type() should be changed to: "Returns given
object's type object".
char or byte :
Python 3.0 will have a byte type and perhaps some
of the later 2.x releases.
c and d
were given the value 500 instead?
Chapter 5
132-133 :: 5.5.3 : Modulus :
We neglected to give a proper example of using the modulus operator.
Add the following to the end of the subsection:
"The modulus operator in Python is like that of C, the percent symbol
(%), and here are some examples of using it:
>>> 5 % 2
1
>>> 8 % 4
0
>>> 6j-7 % 3
(-1+6j)
133 :: 5.5.3 : Exponentiation :
In the final code snippet, we showed an error when raising a number
to a negative power. As of Python 2.2, the operands are correctly
cast to floats as well as the result (this applies to
both the ** operator as well as pow()):
>>> 4 ** -1
0.25
2**31 and the -1. It should be 2**31-1. The extra space needs to be put between the 017 and the + in the 2nd example of exercise 9(a), as in >>> 017 + 32.
Chapter 6
zip() should be in roman font, not
Courier.
in, not in) :
The string data attribute names have changed.
string.uppercase, string.lowercase, string.letters all
have Unicode characters now. To get the pure ASCII versions, use
string.ascii_uppercase, string.ascii_lowercase,
string.ascii_letters.
#!/usr/bin/env
python, and line 5 should refer to string.ascii_letters.
#!/usr/bin/env python
from keyword import kwlist
import string
ALPHAS = string.ascii_letters + '_'
NUMS = string.digits
def main():
print 'Welcome to the Identifier Checker v2.0'
myInput = raw_input('Identifier to test? ').strip()
if len(myInput) == 0:
print "ERROR: no identifier candidate entered"
return
if myInput in kwlist:
print "ERROR: %r is a keyword" % myInput
return
alnums = ALPHAS + NUMS
for i, c in enumerate(myInput):
if i == 0 and c not in ALPHAS:
print 'ERROR: first symbol must be alphabetic'
break
if c not in alnums:
print 'ERROR: remaining symbols must be alphanumeric'
break
else:
print "okay as an identifier"
if __name__ == '__main__':
main()
184 :: 6.4.4 :
This section refers to Section 6.7.4 as that for Unicode when
it should refer to Section 6.8 instead.
string.{center,[rl]just}() methods
now take a fillchar=' ' argument where
fillchar is the character to use for padding.
It should have a (new) footnote "g":
"New or changed in in Python 2.4."
string.*strip() methods now take a
chars=[ \t\n\v\f\r] argument where
chars can be any sequence of leading
and/or trailing characters to remove. It should have a (new)
footnote "f": "New or changed in in Python 2.2.2."
string.rsplit(str=' ',
num=string.count(str) method is
missing: "Same as split(), but search backward
in string." It should have a (new)
footnote "g": "New or changed in in Python 2.4."
string.splitlines() is
incorrect. It should be:
string.splitlines(keepends=False):
"Splits string at all NEWLINEs and returns
a list of each line with NEWLINEs removed unless
keepends=True.
string module was updated with
Unicode equivalent constants as well as the new string templates as
described earlier in section 6.4.2 on p. 182. The paragraph should
end with the final sentence, "Both behave very similarly."
sum() :
In this section, the code example references the reduce()
built-in function. For more details on
reduce(), read ahead to section 11.7.2 in Chapter 11.
232 :: 6.16 :: How to Create and Assign Tuples :
Change "empty tuples" in the first paragraph to "tuples with only
one element" -- see the example below with emptiestPossibleTuple
which is also inappropriately-named since it is a tuple of a single
element, not very empty at all. Empty tuples are specified with just
a pair of parentheses: ( )
buggy.py is really Example 6.5.
(Example 6.4 is queue.py back on p. 229.)
This is just a minor detail. The real problem is that in
lines 11 and 27 of buggy.py, the references to
fac_list erroneously use single quotes. In
other words, it should be using backticks or
repr(), i.e., `fac_list` or
repr(fac_list). This was NOT a typo in
the First Edition however.
zip()
Built-in Function." and refers to the reading in Section
6.13.2.
Chapter 7
266 :: 7.4 :: Table 7.2 :
The second entry should be dict.copy()
not dict.clear(). Also, both the "*" in
dict.iter*() and the "None"
in dict.setdefault() should be in
Courier/mono font. None of these errors are present in
(the equivalent) Table B.9 on p. 1035.
286 :: 7.12 :: Exercise 7-5 :
In exercise 5(c), the parenthesized list should remove reference to the now-obsolete rotor module and add in a few new ones. It should be replaced with: "(see the getpass, md5, crypt [Unix-only], hashlib [2.5], and other cryptographic modules)."
A and B
should be in Courier/mono font, including any operators in between.
Chapter 8
295 :: 8.4 :
Guido's name was messed up in the 1st and 3rd paragraphs during the
final editing phase of the manuscript. Read as only "Guido" or
"van Rossum", not "van Rossum Guido"[sic].
Chapter 9
327 :: 9.2 : Table 9.1 : Footnote "A" :
Universal NEWLINE Support (PEP 278) was added in Python 2.3 not 2.5.
Chapter 10
376 :: 10.3.7 :: Example 10.1 :
cardrun.py
The original installed script was out-of-date. Please
download a new one if your file is older than 2007 Jan 1.
We also installed the example carddata.txt file
as listed on p. 375 as well as updated the alternate version
in the alt directory.
(critical
patch)
cat cardlog.txt command-line
has an extra space that should not be there.
with_suite in the only paragraph on this page.
with_suite, args, traceback, instance, exclass, tb.
try-finally, if the open() call fails,
ccfile will be undefined, resulting in a NameError
exception being thrown, an insult to injury on top of the
IOError exception we received for the failure in
open(). The usual idiom to avoid this situation
is by setting ccfile = None before the
try-finally, then add an
if ccfile: before calling
close(), as in:
ccfile = None
try:
try:
ccfile = open('carddata.txt', 'r')
txns = ccfile.readlines()
except IOError:
log.write('no txns this month\n')
finally:
if ccfile:
ccfile.close()
ccfile = None
try:
try:
ccfile = open('carddata.txt', 'r')
txns = ccfile.readlines()
finally:
if ccfile:
ccfile.close()
except IOError:
log.write('no txns this month\n')
This clarification can also be carried to the second-to-last
paragraph of section 10.8. It is erroneously stated that raising
of string exceptions is not allowed in 2.5, which it is allowed
but generates a warning. Similarly for the catching of string
exceptions, it's really only disallowed starting in 2.7; in 2.6,
a warning is generated.
__debug__ system variable,
after Python 2.2, rather than having values of 1 and 0, it
is a Boolean, thus have values of True and
False, respectively.
(391) The 2nd entry for SystemExit should have a
footnote of "b" just like it is in the entry above. The entire
row should also be grayed out, indicating the change that
occurred back when Python 2.5 was released.
(392) (The 2nd entry for) KeyboardInterrupt should
have a footnote of "c" just like it is in the entry on the previous
page. The entire row should also be grayed out, indicating the
change that occurred back when Python 2.5 was released.
(392) TabError should be indented... it is derived
from IndentationError.
(393) UnicodeTranslateError should have a footnote
of "i" (not "f").
(393) PendingDeprecationWarning should be one word.
(393) Footnotes "b" and "c": the word "subclassed" should be
"derived from".
(393) Footnote "f" is a duplicate of "h" and SHOULD BE REMOVED.
All remaining footnotes and corresponding tagged text should be
adjusted accordingly.
myexc.py
Line 77 is missing the full function call using the module name:
tempfile.mktemp(). Also,
since file() is now a factory function, we've renamed
all such named references to fn. Finally, enter your
own hostnames on line 101 rather than using our test lab computers
which certainly won't work for you.
(critical
patch)
bold.
Chapter 11
foo,
both the standard calls as well as the keyword calls should
be aligned properly.
easyMath.py, only supports addition and subtraction.
The code output demonstrating multiplication is a result of implementing
Exercise 11-16 on p. 474, so you should discard all such output until
you have completed a working solution to that problem.
434 :: 11.6.1 :
In the code snippet featuring tupeVarArgs(), the 2nd
print statement should refer to
arg2 and not
arg1, as in:
print 'formal arg2:', arg2.
bool_func() should instead be represented by the
Boolean values False and True, respectively.
Those values will be integers only prior to Python 2.3.
filter() :
The 2nd paragraph (right beneath the code snippet) mistakenly
refers to having two functions, one of which is main().
(We removed this function, pushed the body out to the global part
of the code, and did not update the text. Rewrite this paragraph
as:
This code snippet contains a function
odd() which
returns True if the numeric argument that was passed
to it was odd and False otherwise. The main portion
of the snippet creates a list of nine random numbers in the range
1-99. [Note that random.randint() is inclusive and
that we could have used the equivalent random.randrange(1,
100), which we recommend because it has the same calling
convention as the built-in function range().]
Then filter() does its work: call odd()
on each element of the list allNums and return a new
list containing just those items of allNums for which
odd() returned True, and that new list
is then displayed to the user with print.
foo(), the calls to bar() should not
have any arguments. We stated immediately above how the previous
code snippet required altering those calls to take a parameter
which was not desired.
random.randrange(), not random.randint()
as the latter will give an error if the random index chosen is
the length of the list.
randrange() has a similar syntax to range()
meaning that it goes up to but does not include the (second or only)
index. Also, the checking of the sequence length is unnecessary as
it will return
False if it is empty. Given these changes, we can
shorten the code to the following:
from random import randrange as rr
def randGen(aList):
while aList:
yield aList.pop(rr(len(aList)))
mult() and use
lambda instead.
Chapter 12
485 :: 12.4.4 :
In the section title, "Import" should be in regular roman
(italicized) font, not Courier Italic.
impter.py filename.
__init__.py is horribly misspelled.
G3.dial,
there is an extra trailing "." that SHOULD BE REMOVED.
newname = importAs('mymodule').
Chapter 13
:-)
__dict__
attribute of the class MyClass we just defined
above, we have the following:". Also, the print
statement for MyClass.__dict__ SHOULD BE REMOVED since
we already displayed the contents of the dictionary for both new-style
and classic classes in the immediately preceding subsection (on the
previous page).
530 :: Core Note :
All references to InstCt should be changed to
InstTrack to match the output below.
TestStaticMethod example, the call
foo = staticmethod(foo) should be dedented to
the same level as the definition of the
foo() function, e.g.,
class TestStaticMethod:
def foo():
print 'calling static method foo()'
foo = staticmethod(foo)
SortedKeyDict example output, the
supposedly sorted list when using
keys() is out-of-order due to an error correction:
"xin-yi" was misspelled as "hsin-yi", and the edit was made without
reordering the list correctly. it should be:
By keys(): ['hui-jun', 'xin-yi', 'zheng-cai']
time60.py
The documentation string for
__init__() on line 7 should
indented one level (four spaces to the right).
(minor
patch)try-except
and try-finally statements
together (lines 30-38)."
descr.py
For this code to work with Python 2.5 and newer, delete line 31.
For this code to work with any version of Python, indent
line 34 one level (four spaces to the right). For the
__set__() method, the open() statement
on line 29 should really be moved to the innermost try
block immediately below it (between lines 31-32), and the
succeeding except should also be monitoring for
IOError — just like in the above
__get__() method. Less importantly, name
should not not have a default value as it does now on line 9. Below,
we post two patches, one for users of Python 2.5 and newer as well
as one for those using Python 2.4.3 and older.
(critical
patch
[diff];
pre-2.5 patch
[diff])property()
Built-in Function :
The last part of the final sentence in the first complete paragraph
at the top of the page before the definition of the
ProtectAndHideX class should be changed to the following:
"... encrypting it by using the bitwise complement
operator:". (The XOR operator is binary and not used in
this example.)
property()
Built-in Function :
I must have done this really late at night as the code for
the HideX class will not work with using
the property() factory function as a decorator
(in any version of Python). You will always
have to use the
x = property(**x()) syntax. Likewise, the text
of Exercise 13-21 on p. 625 has to be changed (see below).
The reason why it does not work is because the defition of
x() will not automatically return the inner function
objects so that the property can be created. That's why you
still need to execute
x() in order to get it to call
locals() so that the
fget() and
fset() names and objects are returned. How these
objects help create the property is still the main point of
Exercise 13-21. In the code, remove the
decorator and add
@propertyx = property(**x()) right beneath the function
declaration. Let's also change the class name to something
more appropriate for this example:
#!/usr/bin/env python
'ProtectAndHideX.py -- protect the "x" attribute'
class ProtectAndHideX(object):
def __init__(self, x):
self.x = x
def x():
def fget(self):
return ~self.__x
def fset(self, x):
assert isinstance(x, int), \
'"x" must be an integer!'
self.__x = ~x
return locals()
x = property(**x())
inst = ProtectAndHideX(10)
print 'inst.x has a value of:', inst.x
inst.x = 20
print 'inst.x has a value of:', inst.x
inst.x.fset(40) # sorry!
print 'inst.x has a value of:', inst.x
inst.x has a value of: 10
inst.x has a value of: 20
Traceback (most recent call last):
File "
'$1,234,567.89',
and that string should be in Courier/mono font.
619 :: 13.18 :: Example 13.11 :
moneyfmt.py
Line 13 of __repr__() should be replaced
with a call to repr(), i.e.,
def __repr__(self):
return repr(self.value)
The original code, including the source in the download area, has
return `self.value` which is still valid for now, but
the single backticks will be deprecated some point by repr().
enqueue() and
dequeue() functions refer to modifying a "list"
when it should be "queue." Also, this problem refers to Example
6.3 for motivation, but it should really be Example 6.4 instead.
__add__() and into one of the other methods of this classfile?
If so, which one and why would it make sense to do so?
property() as a decorator does not work for
any version of Python. There is also multiple typos in
the "alternate syntax" (which turns out to be the only syntax
that can be used). This problem should be completely
rephrased as:
Toward the end of section 13.16.4, we used the
syntax
x = property(**x()) to create a property
for the
x attribute for the
HideX class. How does this idiom, including the
enclosed call to x(), actually create the property?
Chapter 14
lambda Expressions" :
In the (sub)section title, "lambda" should be in
normal roman font, not Courier.
% prompt to that of sh/bash: $.
The first one is misindented too far... move it to the left to align
it with the rest of the program output.
def foo... should really be
def bar....
print statement for import2.py
needs to be indented to the right one more space.
eval() should not be italacized.
os.popen() should be
in Courier font.
os.system() at the top of the page
should not be in boldface. Also, in the code for the "Replacing
os.system()" section, remove the superflous
import os line completely.
SystemExit in the second-to-last sentence on this page
should be one word.
668-669 :: 14.10 :: Exercise 14-1 :
There should be 13 exercises in this chapter:
exec
versus eval()". Only exec
should be bolded, not the remainder of the problem.
os" module name should be in
Courier font.
-ef" argument of the functional style call should be
parenthesized, as in: sort(grep(ps(-ef), root), -n, +1).
funcAttrs.py is Example 14.3.
Chapter 15
697 :: 15.3.13 :: Example 15.1 :
rewho.py
f.readlines() can be shortened to the file iterator
f.
(minor
patch)
Chapter 16
tsUclnt.py
Line 20 should simply be print
data
(critical
patch)
clientConnectionFailed().
742 :: 16.7 :: Exercise 16-5 :
The URL for the socket example has changed to
http://www.python.org/doc/current/lib/socket-example.html
Chapter 17
749 :: 17.2.2 : Figure 17-1 :
The diagram was not drawn correctly to specification. Here are
some fixes to repair it:
loc.close()."
if it is there
to avoid clutter...".
os.unlink(FILE)
in case the file does not exist."
else clause (lines 35-42)."
xhdr(hdr, artrg[, ofile])
Line 60 is a generator expression.
It works like a list comprehension only it does lazy evalution and
does not build the entire results list when this line is executed.
(The entire dataset,
data, is already taking enough
memory as it is!) Rather, each line is only processed when its turn
comes up in the loop below on line 62. Generator expressions were
added in Python 2.4, so if you are using an earlier release, the
easiest fix while minimizing memory use is to add a new statement
in between lines 62 and 63: line = line.rstrip(). If
memory is not a concern, then just use a list comprehension instead
(change the parentheses to square brackets).poplib.POP3_SSL class which will perform mail
transfer over a secure connection provided the appropriate
credentials are supplied. Let's take a look...."
mailbox module and email package."
Chapter 18
setDaemon() method
name should not have a hyphen/dash.
= for
the join() method's arguments.
Queue
module is missing a few items and needs to be updated... stay
tuned for the exact corrections/updates.
Chapter 19
NEW (May 08)
833 :: 19.3.5 :: Line-by-Line Explanation :: Lines 1-18 :
The functional module is renamed to
functools.
834-835 :: 19.3.6 :: Example 19.6 :
Lines 15 and 17 should be indented like the rest of the lines
in the __init__() method.
Chapter 20
net_loc
should be in Courier Bold Italic.
Adjust line 20 so it is flush with the other lines of code.
Change the filename to urlopenAuth.py (see next erratum).
urlopenAuth.py (see next erratum).
The current name (urlopen-auth.py) will not allow the module
to be imported since '-' is not a valid Python identifier.
__init__() and filename()
methods (lines 15-34) are not indented properly... there should be 4
spaces of indentation for these methods.
$ python -m CGIHTTPServer [port].
cgi-bin is accidentally titlecased twice.
885 :: 20.5.4 :: Example 20.5 :
The if clause (line 49) should be indented at
the same level as
the else clause (line 51).
string.split() should be
str.split() to indicate usage of the
split() method of strings rather than the
split() function of the
string module.
wsgiref module,
"application" should be in plural, e.g., "applications."
Chapter 21
errorhandler() should
be in Courier Italic. There should also
be some text just able this table which describes the
error-handling mechanism further, such as, "An option for
database adapter writers to allow for user-defined error
handlers is available. Both Connection objects
as well as Cursor objects (see next section)
allow module authors to define an errorhandler()
method for this purpose.
description attribute description, both
name and type_code at
the end should be in Courier Italic.
sqlite3 module).
Courier.
Example 21.1: 54, 107-115, 136
Example 21.2: 56, 64, 75, 99
Example 21.3: 71
elif clause.
try-except should be in bold.
getattr(orm, 'drop') call, and further
on, self.users should be in mono (Courier)
font. Finally, there are too many blank lines above and
below the next section (lines 82-84).
Chapter 23
stock.py
Line 20 should be u.close().
(critical
patch)olook.pyw
For running the
demo),
the outlook() function should be named
olook() (to match the name of the module)
because that is what the demo expects. Since we are
lazy, we just simply create an alias to the original
function by inserting a new line 31 which reads:
olook = outlook.
If you're not going
to run it, this change is not necessary.
(minor
patch)estock.pyw
Line 43 should be u.close().
Also, on line 25, "as" should not be bolded.
(critical
patch)
Appendix B
NEW (May 08)
1025 :: Table B.3 :
In footnote (b), it refers erroneously to Table 5.2... it should be Table 5.3.
1038 :: File Object Methods and Data Attributes :
The section title has "Attributes" misspelled... remove the extra "o".
CREDITS
Thanks to the many readers who have provided invaluable feedback
and corrections in this section. They include but are not limited
to: David Librik,
Sebastian Strempel,
Loek Engels,
Steven Wayne,
Viraj Alankar,
Johan Neven,
Dave Hines,
Barrett Shiff,
Harold Trammel,
Marie-Cécile Baland,
Greg Nofi,
Mark Ackerman,
Tony Tang,
Adil Lotia,
Satoshi Tanabe,
and others.
![[powered by Python]](images/pypow.gif)