[WWW] [Core Python Programming]

Welcome to the Errata page for Core Python Programming!

This page is broken down into 2 main sections of errata, the text of the book and the source code. Each errata item follows this format:

Page :: Section (may also have Figure, Table, or Example number) : Correction

  • Scroll down to Text Errata
  • Scroll down to Code Errata


    Text

    FrontMatter

    xx :: Preface : The last 2 sentences of the "Style" section incorrectly indicate a mini-reference guide in the last section of the book. Rather than a mini-reference guide, we replaced it with 5 chapters on regular expressions, network programming, multithreaded programming, GUI programming with Tkinter, and Web Programming.

    xxiv :: Optional Sections : edit to 2nd paragraph: "... can skip the first chapter and go straight to Chapter 2... absorb Python and be off to the races."


    Chapter 1

    16 :: 1.7.3 (Unix): remove "either" on 2nd line


    Chapter 2

    26 :: 2.1 (page bottom) : add this output to the print statement:
    >>> print "%s is number %d!" % ("Python", 1)
    Python is number 1!

    27 :: 2.2 : reword parenthesized segment in the 3rd sentence to: (Use the string.atoi() function for Python versions older than 1.5.)

    27 :: 2.3 : code does not accurately reflect interpreter; change code to:

    >>> # one comment
    ... print 'Hello World!'   # another comment
    Hello World!

    32 :: 2.8 : "aLlist" at bottom of first interactive example should be changed to "aList"

    35 :: 2.12 : "loop #5" of interactive example should be deleted

    36 :: 2.13 : In the final print statement, the items to be printed are missing their opening parenthesis. It should be:

    ...    (who, ((what + ' ') * 4))

    40 (top) :: 2.16 : first sentence from preceding page should be changed to read: "... declared before they can be called." (Functions do not have types in Python.)

    44 (top) :: 2.17 : Interactive example is missing "My name is..." as in:

    >>> foo2.showname()
    Your name is Jane Smith
    My name is __main__.FooClass


    Chapter 3

    62 :: 3.4.1 (Core Style): Final sentence of 1st paragraph should refer to this "Core Style" not "Core Note".

    68-71 :: 3.6 : Example (not Listing) 3.1 : On line 25, there is a cryptic reference to sys.exc_info()[1] and no explanation on p. 71. As you will discover, sys.exc_info() is a function which returns a list containing an exception class, an exception object, and a traceback object. The [1] simply refers to the 2nd item (exception object) of the list. It is no different than an operation similiar to:

    >>> aList = [123, 'xyz', 45.67]
    >>> print aList[1]
    >>> xyz

    73 :: 3.7 : Exercise 3-8 : 1st sentence should refer to string.find() the function, not module


    Chapter 4

    76 :: 4.1.1 : 2nd sentence should refer to Section 2.14 not 3.14.

    77 :: 4.2 : Core Note : "... wrapping a type around a Python class..." should be "... wrapping a class around a Python type...." Also, the last sentence should say, "See Sections 13.15 and 13.16," not 13.18.

    84-85 :: 4.5.2 :: Examples 1, 2, 3 and Figures 4-1 and 4-2 : Python caches low integers (and some strings), so using integer 4 in these examples (and in the figures) may result in the same object being referenced. If this is your experience, change the integers to floats and try again, i.e.,

    >>> foo1 = 4.0
    >>> foo2 = 1.0 + 3.0
    >>> id(foo1)
    134668004
    >>> id(foo2)
    134667956
    

    86 :: 4.5.2 :: This "Core Note" sidebar is missing at the end of section 4.5.2:

    CORE NOTE: Interning
    Smaller integers, identifier names, and shorter strings which are similar to identifier names which may be used often in the code will be cached internally, a process known as interning. If an object is interned, then multiple references to such objects will be identical. (In other words, common objects such as these will only be created once and shared, otherwise it is a waste of resources to have multiple objects with the same value which are created and referenced often.)

    If you have tried the example in this section with your interpreter, you will discover that "foo1" and "foo2" would refer to the same object (when you use a is b or id(a) == id(b))! Don't worry if you get that... it is not a mistake by the interpreter. Change the integer 4 to float 4.0 and see if you get the expected result. Also see section 14.3.6 for more about interning.

    91 :: 4.6.3 : ">>> type(Abc)" of interactive example assumes a declared class named Abc


    Chapter 5

    105 :: 5.2.2 : separate the last 2 long integers in the 2nd line of the long integer examples. 0xDECADEDEADBEEFBADFEEDDEAL and -5432101234L are different longs.

    107 :: 5.4 : separate the 2nd and 3rd to last complex numbers in the final line of Section 5.4. 0+1j and 9.80665-8.31441J are are different complex numbers.

    109 :: 5.5.1 : text reference should be the Python Language Reference Guide.

    110 :: 5.5.1 : output on the second interactive example should be 999998000001L, not 99999B000001L.

    118 :: 5.6.2 : ndig is the optional second argument, not third.


    Chapter 6

    133 :: 6.1.1 : In the section referring to the repetition operator, the text should read, "The syntax for using the repetition operator..." rather than referring to the "membership operators."

    134 :: 6.1.1 : Figure 6-2 : There should be no space between sequence and [:] in the caption.

    145 :: 6.3.2 : Core Tip : First print statement should be indented in the while loop.

    147 :: 6.4.1 : In the 2nd sentence, "pack" should really be "lack."

    152 :: 6.4.2 : There should be no "our RE matched:" strings in either of the statements in the interactive output at the end of this section.

    153 :: 6.4.3 : There should be no space between ur and the quoted Hello World string.

    155 :: 6.6 : Table 6.6 : string.alnum is misspelled with a 1 rather than an "L".

    176 :: 6.11.2 : There should be no string 'park' in the concatenation of str_list + num_list in the output near the bottom of the page.

    182 :: 6.13 : Table 6.10 : The description for the pop() list method is incorrect. Rather than giving the object to remove, you give the index of the object to remove, defaulting to the last item of the list if no argument is given. So the row should read as:

    list.pop(index=-1) -- removes and returns object at given or last index from list

    186 :: 6.14.1 : Example 6.2 : call to showmenu() on line 47 should be indented.

    193 :: 6.14.2 : final sentence should refer to Section 13.16 rather than 13.18.

    193 :: 6.15 : first sentence in "How to Create and Assign Tuples" section should start as "Creating and assigning tuples..." not lists.

    194 :: 6.15 : first line of interactive code should read:
    >>> aTuple[1:4]

    194 :: 6.15 : final sentence should refer to removing an entire "tuple," not list, keeping in mind again, that most of the time, programmers will just let an object go out-of-scope rather than explicitly deleting an object.

    201 :: 6.18 : description of UserList module should refer to Section 13.16 rather than 13.18

    209 :: 6.20 : Exercise 6-9 : 1st sentence should refer to Exercise 5-13, not 6-13


    Chapter 7

    (none reported at this time)


    Chapter 8

    242 :: 8.5.2 : Iterating by Sequence Item : There should be an equal sign between "nameList" and the list of names, e.g.,
    >>> nameList = ['Walter', "Nicole", 'Steven', 'Henry']

    244 :: 8.5.4 : In the for-loop at the bottom of the page, the C variable i is misspelled and should be eachVal: for (eachVal = 2; eachVal < 19; eachVal += 3) {...

    252 :: 8.10 : Exercise 8-9 : The actual problem does not follow the description of Fibonacci numbers. The rest should read: Write a routine such that given N, display the value of the Nth Fibonacci number. For example, the first Fibonacci number is 1, the 6th is 8, and so on.


    Chapter 9

    261 :: 9.3.4 : In the final paragraph, "The flush() method," sentence is incomplete. Generally data is stored or queued temporarily until it is written to the file. So the sentence should read, "Rather than waiting for the (contents of the) output buffer to be written to disk, calling the flush() method will cause the contents of the internal buffer to be written (or flushed) to the file immediately."

    267 :: 9.5 : In the paragraph for sys.stdout.write() near the middle of the page, the 2nd sentence should read that "readline() executed on sys.stdin preserves the NEWLINE..." and not "readline."

    268 :: 9.5 : The 2nd sentence at the top of the page should read: 'The names "argc" and "argv"....'

    275 :: 9.7 : The pseudocode in the 2nd section is missing one line with a call to os.chdir():

    >>> os.mkdir('example')
    >>> os.chdir('example')
    >>> cwd
       :
    

    Also, the exception with os.listdir() is intentional, to show you the error which results when no directory name is given to the function.

    276 :: 9.7 : The pseudocode in the 2nd section is missing the assignment of the allLines variable:

    >>> file = open(path)
    >>> allLines = file.readlines()
    >>> file.close()
       :
    


    Chapter 10

    306 :: 10.3.10 : "# executes regardless of exceptions" comment should be on a single line of the finally clause.

    315 :: 10.6.1 : first sentence of 2nd to last paragraph should italicize without any parameters.

    320 :: 10.8 :: Table 10.2 : TableError should be TabError


    Chapter 11

    348 :: 11.5.2 : first line from output of grabweb.py improperly displayed on 2 lines

    350 :: 11.6.2 : print statement displaying 1st formal argument in dictVarArgs() function should read as:

    print 'format arg1:', arg1

    ... and not ...

    print 'format arg1:', dictVarArgs

    350 :: 11.6.2 : in example execution of dictVarArgs(), 2nd invocation should set arg1 not a to 'mystery'

    353 (top) :: 11.6.3 : add final new sentence before Section 11.7: Prior to 1.6, variable objects could only be passed to to apply() with the function object for invocation.

    362 :: 11.7.2 (filter()) : pseudocode is improperly indented... the code should look like:

    def filter(bool_func, sequence):
        filtered_seq = []
        for eachItem in sequence:
    	if apply(bool_func, (eachItem,)):
    	    filtered_seq.append(eachItem)
        return filtered_seq

    363 :: 11.7.2 (filter()) : first round code for oddnogen.py is also indented improperly... it should appear as:

    from random import randint
    
    def odd(n):
        return n % 2
    
    def main():
        allNums = []
        for eachNum in range(10):
    	allNums.append(randint(1, 101))
        oddNums = filter(odd, allNums)
        print len(oddNums), oddNums
    
    if __name__ == '__main__':
        main()

    367 :: 11.7.2 (map()) : change the reference of "Zip()" to zip() (font should also be Courier in another reference on the bottom of p. 369).

    372 :: 11.7.2 (reduce()) : mathematical operation for the example is missing 2 left parentheses: ((((0 + 1) + 2) + 3) + 4) => 10.


    Chapter 12

    (none reported at this time)


    Chapter 13

    414 :: 13.4.1 : 1st print statement of C.foo down at the bottom should output 100 not 0

    441 :: 13.10.2 (Core Note) : output of instanantiation is incorrect... it should be:

    >>> c = C()
    calling C's constructor

    449 :: 13.12 : section title should be "Types vs. Classes/Instances"

    454 :: 13.13.1 : output of last interactive example should not be indented:

    >>> print myPair
    (-5, 9)

    463 (top) :: 13.13.2 : first paragraph is for Lines 42-54


    Chapter 14

    (none reported at this time)


    Chapter 15

    559 :: 15.4 :: Figures 15-2 and 15-3 : these figures will NOT make sense because you cannot see the middle set of boxes... in Figure 15-2, draw a box around "Thu Feb 15 17:46:04 2007::uzifzf@dpyivihw.gov::117159036" and another box around "4-6-8", and in Figure 15-3, the boxes should around "Thu Feb 15 17:46:04 2007::uzifzf@dpyivihw.gov::" and "1171590364-6-8".


    Chapter 16

    (none reported at this time)


    Chapter 17

    607 :: 17.5.1 : Last sentence in 1st paragraph should refer to line 16, not 17. The next paragraph should refer to lines 29-30 in Example 17.6, not 28-29.


    Chapter 18

    631 :: 18.3.4 : Figure 18-4 shows the state of the GUI after the user moves the scale/slider to a value of 36. The default setting for the scale when the application tkhello4.py (see Example 18.4 on p. 630) starts is 12.


    Chapter 19

    642 :: 19.1.1 : last sentence of the 2nd complete paragraph should be more clear and accurate: "Its (HTTP's) responsibility is not to route or deliver messages -- TCP and IP handle that -- but to transmit and/or deliver HTTP messages.

    664 :: 19.5.1 : "CN" Core Note logo should be "CT", meaning a Core Tip logo.

    682 :: 19.5.1 : Example 19.6 : The first two words of the description of this code should read, "This script..." rather than "The crawler...".

    684 :: 19.5.1 : Example 19.6 : or on line 108 of advcgi.py should be for. (The source code is correct though.)

    690-691 :: 19.7.1 : output from the myhttpd.py webserver wraps... lines of output should be on single lines.


    Chapter 20

    (none reported at this time)


    BackMatter

    730 :: Appendix B : "Freidl" should be spelled "Friedl"... sorry Jeffrey!


    Code

    (Minor problems do not prevent the program from running, but critical bugs means that the code as-is will not execute.)

    Chapter 14

    520 :: 14.7.1 :: Example 14.4 : args.py
    Missing the opening single quote after the print keyword on line 7. (critical patch)

    Chapter 16

    575 :: 16.3.3 :: Example 16.1 : tsTserv.py (
    new script) (diffs)
    An additional pair of parentheses is required around the %-operator arguments ctime(time()) and data; i.e., it must be a tuple. (critical patch)

    Chapter 18

    632-634 :: 18.3.5 :: Example 18.5 : listdir.py (alternative version only) (new script) (diffs)
    Removed dependency on old 'ls' module which no longer exists. (critical patch)

    Chapter 19

    654-656 :: 19.3 :: Example 19.1 : crawl.py (new script) (diffs)
    Some old variable names hung around; also needed OS-independent path separator.
    (critical patch)

    662 :: 19.5.1 :: Example 19.2 : friends.htm (new HTML file) (diffs)
    Missing default value of "NEW USER".
    (minor patch)

    666 :: 19.5.2 :: Example 19.4 : friends2.py (new script) (diffs)
    Missing default value of "NEW USER".
    (minor patch)


    [Core Python Programming]
    [powered by Python]
    © 2001-2009 CyberWeb Consulting
    corepython (at) yahoo (dot) com