Errata

Introducing Python

Errata for Introducing Python

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.

The following errata were submitted by our customers and have not yet been approved or disproved by the author or editor. They solely represent the opinion of the customer.

Color Key: Serious technical mistake Minor technical mistake Language or formatting error Typo Question Note Update

Version Location Description Submitted by Date submitted
n/a
Chapter 10. Oh Oh: Objects and Classes, Section Class and Object Attributes

IMO this paragraph is a bit confusing.

In the third paragraph it says, "If you change the class attribute later, it won't affect existing child objects". From the user perspective, this does *seem* to apply for the *given case* in this section, where the class attribute is shadowed by the created object attribute in the second paragraph, due to their coincidental names.

In the general case, where no object attribute with the same name as the class attribute exists, the class attribute in the already created object will be affected, since they are shared across all instances:
```
>>> class Fruit:
... color = 'red'
...
... blueberry = Fruit()
>>> blueberry.color
'red'
>>> Fruit.color = 'blue'
>>> blueberry.color
'blue'
```

Anonymous  Aug 08, 2021 
Printed Page pg.450, chap.19 Books
second bullet point

Beazley, David M. Python Essential Reference (5th edition) Addison-Wesley, 2019 is not a released title,
there is however a fourth edition a/v for sale at book vendors.
I also see available the Python Distilled which looks similar, but that's the wrong date, it appears. The theme I found of knowing and theorizing through book knowledge is interesting, I'm interested in the book we are referring to, to learn through. Please point me in the right direction?

Anonymous  Nov 13, 2023 
ePub Page Page 449
Example 15-8. cf2.py

I am new with Python. Going throught the book and so far I was able to understand all the sample code. Sometime I had to ajust and it was fine. In the main function of cf2.py example there are 2 for loops that begin as follow:

for val, result...

For both of them I get an error message that I was not able to get to work.
The error message is:

TypeError: cannot unpack non-iterable float object.

It works when I remove the val variable in the for loops.
I am using Python version 3.11.5 on Windows 11. I am also getting the same error message when running the code on Linux (Ubuntu).

Please can you provide some suggestion on why I am getting this error?

Thank you.

Richard Desrosiers  Nov 29, 2023 
Printed Page 9
bottom three lines on p. 9

In item 14 at the bottom of the page, it says, "Notice that this line and the next two are indented." It should say, "Notice that this line and the next three are indented." (The next three lines are lines 15, 16, 17, which are all indented.)

Mark Daniel Ward  Jun 17, 2020 
Printed Page 13
lines 20-21

in the phrase ... "are successors to C and C++ that avoid" ... we have a line break in the middle of the name of the language C++. We have C at the end of line 20, and ++ at the start of line 21. This looks very strange, to allow a line break in the middle of the name C++.

Mark Daniel Ward  Aug 01, 2020 
Printed Page 17
7 lines from the bottom

In the phrase "it will be around for while"
it should say "it will be around for a while"

Mark Daniel Ward  Oct 02, 2020 
PDF Page 25
Last paragraph

You state that "Python is strongly typed, which means that the type of an object does not change, even if its value is mutable".
This is VERY CONFUSING statement.
I guess you mean that you CAN change value after assigning value to a variable. Otherwise this is WRONG statement since Python is dynamically typed language:

theBool = False
print(theBool)
print(type(theBool))
theBool = "string234"
print(theBool)
print(type(theBool))

Output:
False
<class 'bool'>
string234
<class 'str'>

Eugene  Jul 26, 2021 
Printed Page 29 and 32
page 29, end of the section, and page 32, near the top of the page

On page 28, we have
>>> x = 5
>>> y = x + 12
>>> y
17

So it would make more sense to write the examples on pages 29 and 32 this way:
>>> y = 17
>>> x = y - 12
>>> x
5

That way, the examples on pages 29 and 32 are consistent with the example from page 28. This is not an error, but just a suggestion for consistency with page 28.

Mark Daniel Ward  Oct 05, 2020 
PDF Page 45
Get a Slice to Extract Items by Offset Range

wrong >>> marxes = ['Groucho', 'Chico,' 'Harpo']

right >>> marxes = ['Groucho', 'Chico' , 'Harpo']

Konstantin Klenkov  May 06, 2021 
Printed Page 49
3rd paragraph

The book says:

A googolplex is 10**googol (a thousand zeroes, if you want to try it yourself).

but actually it should say:

A googolplex is 10**googol (1 followed by a googol of zeroes, if you want to try it yourself).

[Note to the author: If you type 10**googol in python3, it will never complete, because the computer is unable to write 1 followed by a googol of zeroes.]

Mark Daniel Ward  Oct 10, 2020 
Printed Page 54
example at the bottom of page 54

"add the first five digits"
should say:
"add the first four digits"

(Someone might argue that, on page 54, we are adding five digits, namely 0 + 1 + 2 + 3 + 4 = 10, but if we look ahead to the top of page 55 (where we do it in one step), we are only adding four digits, namely, 1 + 2 + 3 + 4 = 10. Moreover, it is pretty clear that the "0" in the sum on page 54 is just to initialize the sum. So I think the book should say "add the first four digits", please.)

Mark Daniel Ward  Oct 17, 2020 
ePub Page 56
2nd

“Python is calculating the subtraction on the righthand side, remembering the result, and then assigning it to a on the left side of the + sign. It’s faster and neater than using a temporary variable.”

Instead of + it should be =.

Daniel  Dec 07, 2021 
Printed Page 66-67
The tab example at the bottom of page 66 and top of page 67

The spacing on the tabs in this example is not consistent. It should look like this:

>>> print('\tabc')
abc
>>> print('a\tbc')
a bc
>>> print('ab\tc')
ab c
>>> print('abc\t')
abc

In the printed book, the first tab is 4 spaces, and the second tab is 4 spaces, but the third tab is 6 spaces (and, of course, we cannot tell how wide the fourth tab is). On the other hand, in the Python interpreter, all of the tabs should be the same width. Therefore, in the book, the tab spacing should consistently be the same width as well.

Mark Daniel Ward  Oct 23, 2020 
Printed Page 72
line 7

Line 8 says letters[-51:-50]
OK, with line 8 in mind, now please consider a change in line 7.

Line 7 currently says:
"From 51 before the end to 50 before the end:"
but line 7 should (please) be corrected to say:
"From 51 before the end to 51 before the end:"

Here are two reasons for making this change.
(1) On page 71, letters[-6:-2] is referred to as "from 6 before the end to 3 before the end"
(2) We can build an example, e.g.,
doubleletters = letters + letters
and then we see that
doubleletters[-51:-50]
is only one character, namely, 'b', which is the same as:
"From 51 before the end to 51 before the end:"

So line 7 needs a correction, please! Thank you for considering.

Mark Daniel Ward  Oct 24, 2020 
Printed Page 76
in the duck example

In the duck example (i.e., when word = "duck")
there are two identical lines, namely, this line of code occurs twice:
>>> poem.rfind(word)

Mark Daniel Ward  Oct 27, 2020 
Other Digital Version 78
Walrus operator section

incorrect: if diff := tweet_limit - len( tweet_string) > = 0:

`diff` is going to be assigned to a boolean. This is unintentional by the author because the author wrote below: `print("Went over by", abs(diff))`, which implies the author expects an integer.

correct: if (diff := ...) >= 0

Lubanovic, Bill. Introducing Python (p. 78). O'Reilly Media. Kindle Edition.

Anonymous  Sep 10, 2021 
Printed Page 85
question 5.5

In question 5.5, where we "assign values to variable strings" the variable 'amount' is missing from the list, even though 'amount' is one of the variables in the form letter.

Mark Daniel Ward  Oct 28, 2020 
Printed Page 91
First sentence after Generate Number Sequences with range()

The first sentences of the Generate Number Sequences with Range have an errand period where there should be a comma. To wit:

"The range() function returns a stream of numbers within a specified range. without first having to..."

That period should be a comma.

Lee Creighton  May 20, 2020 
Printed Page 91
Last paragraph starting with "Like zip()..."

Although the paragraph says "Like zip(), range() returns an iterable..." it turns out that zip() isn't introduced until p. 110. This is almost certainly a holdover from the first edition when this paragraph immediately followed a section on zip. Said paragraph now shows up on p. 110, much later than the p. 91 where zip() is brought up as an example.

There are lots of examples using zip() on p. 92 that are casualties of this same error.

Lee Creighton  May 20, 2020 
Printed Page 91
the section called Generate Number Sequences with range()

On page 91, in the section called Generate Number Sequences with range(), there are two typo's:

On the first line of this section, it reads "within a specified range. without"
and this period should be removed.

In the third paragraph in the section, we have:
"Like zip(), range() returns an iterable object"
but we have not (yet) learned about the zip() function at this point in the book. In the first edition of the book, the zip() function was covered shortly before this, so it made sense, but it does not make sense to mention the zip() function at this point in the second edition of the book.

I hope those two corrections are helpful for you!

Mark Daniel Ward  Nov 04, 2020 
Printed Page 92
question 6.3

In question 6.3, on line 3, please change:
found it!
to be (instead) like this:
'found it!'
with single quotes around it. That way, it is consistent with question 6.2 and also consistent with the other things in question 6.2 and 6.3, such as 'too low' and 'oops' (which both have single quotes around them).

Mark Daniel Ward  Nov 04, 2020 
Printed Page 92
question 6.2

In line 3 of question 6.2, in the phrase
"is less than guess me"
there is an underscore missing. It should say:
"is less than guess_me"

Mark Daniel Ward  Nov 04, 2020 
Printed Page 94
After "You could enclose them in parentheses..."

Center pf page, you have

"You could enclose them in parentheses and get the same tuple:

>>>one_marx = ('Groucho',)
>>>one_marx
('Groucho',)"

However, ('Groucho',) does not produce a tuple, but a string. The top of page 95 confirms this when it says

">>> type ('Groucho',)
<class 'str'>

Lee Creighton  May 20, 2020 
Printed Page 95
3rd code example

password and icecream are strings. They each need a trailing comma to be tuples.

Anonymous  Jul 07, 2020 
PDF Page 96
Example code under "Modify a Tuple"

Line 2 of the 1st example contains "t2 = ('Flop,')". The PyCharm IDE treates this as a string, not a tuple. The next line of code "t1 + t2" attempts to concatenate a tuple and string producing an error "TypeError: can only concatenate tuple (not "str") to tuple".

Changing line 2 to "t2 = ('Flop','x')" corrected the error.

john chapman  Nov 26, 2021 
Printed Page 97
Examples under Create with []

Under Create with [] there are several examples, including the first one which says

>>> empty_list = [ ]

There is a space between the brackets, which is incorrect and inconsistent with the way you present empty lists in other places in the book.

Lee Creighton  May 20, 2020 
Printed Page 108
1st paragraph of "Copy Everything with deepcopy()" section, 2nd sentence

The specified sentence on p. 108 includes "tuple" as an example of a mutable value. This directly contradicts p. 93, paragraph 4 which states that "Tuples are immutable".

From my other research on this topic, it appears that while the values in the tuple may themselves be mutable, the actual tuple is not.

The statement on p. 108 may require disambiguation, although the gist is fairly clear.

Nathan Dias  Dec 20, 2020 
Printed Page 111
examples following the paragraph that starts "Chapter 8 shows you..."

You give an example of changing the days of the week from English to French.

>>>English = 'Monday', 'Tuesday', 'Wednesday'
>>>french = 'Lundi', 'Mardi', 'Mercredi'

Note that days of the week are not capitalized in French, so the second line should say

>>>french = 'lundi', 'mardi', 'mercredi'

Lee Creighton  May 20, 2020 
Printed Page 119
Paragraph above "Add or Change an Item by [key]

Read the sentence above "Add or Change an Item by [key]:
"The section 'Iterate Multiple Sequences with zip()" on p. 1110 introduces you to the zip() function,..."

Do you thin the referred-to section is upcoming or in the past? It is in fact in the past, on p. 110, meaning IMHO "introduces" should be "introduced", especially since your expectation, as stated in the Preface, is that these chapters are to be read in sequence.

Lee Creighton  May 20, 2020 
Printed Page 119
Problem 8.12

You ask the reader to use a generator comprehension to return a string (etc.) but generator comprehension are no longer in this chapter since the revision. They don't appear until the next chapter on p. 158, so perhaps this exercise should be moved or deleted.

Lee Creighton  May 20, 2020 
Printed Page 128
1st section

Iterating through a dictionaries keys, the code is:

for card in accusation: # or, for card in accusation.keys():
print(card)

The # or, I believe is unnecessary.

Paul Marshall  Dec 29, 2022 
ePub Page 142
"Compare Tuples" section

The brief explanation under "Compare Tuples" says that "This works much like list comparisons". But lists haven't even been introduced yet at this point.

Presumably the more detailed explanation found later in chapter 7 under "Compare Lists" should be moved here, and "Compare Lists" should refer back to it ("This works much like tuple comparisons").

Anonymous  Oct 10, 2020 
Printed Page 143
code block below center that starts with def commentary(color):

For some reason, single and double quotes are mixed in this code block It's unnecessary and probably not pythonic to do it that way, so you may want to be consistent with one quote style (Single quotes is my guess) in the next printing.

Lee Creighton  May 20, 2020 
Printed Page 163
opening para, "Uses of _ and __ in Names"

Missing description and example of single-underscore role.

P Tufts  Aug 15, 2020 
ePub Page 164
3rd to last REPL block of f-strings section

>>> f'{thing =}, {place =}'
thing = 'wereduck', place = 'werepond'

------------------------------------------------------

Spaces (or lack of same) are taken literally within f-string braces, so the actual output in Python 3.8.1 is:
thing ='wereduck', place ='werepond'






Gregory Sherman  Jul 17, 2020 
ePub Page 164
2nd to last REPL block of f-strings section

See error report of "3rd to last" - same problem with output having extra spaces

Gregory Sherman  Jul 17, 2020 
ePub Page 164
3rd & 2nd to last REPL blocks of f-strings section

In addition to the issue with spaces, the entire output strings will be surrounded by double quotes.

Gregory Sherman  Jul 17, 2020 
ePub Page 165
last REPL block of f-strings section

>>> f'{thing = : >4.4}'
thing is 'were'
---------------------
Actual output is:
'thing is were'

Gregory Sherman  Jul 17, 2020 
Printed Page 202,203
last paragraph on p.202 and several places on p.203

On last paragraph of p.202, the subdirectory should be named sources instead of choice to be consistent with the line "from sources import fast, advice" in Example 11-7 on page 203. Changes should also be made on page 203 on the references to the locations of fast.py and advice.py

Jeng-nan Shiau  Jun 23, 2020 
Printed Page 205
last code example in "Relative and Absolute Imports" section

Original text:
If it’s under a sibling directory called creatures: from ..creatures import
rougarou.


Is the correct path " ../creatures"?

Ruey-Cherng Yu  May 15, 2022 
PDF Page 241
code around the middle

>>> data[20:24]0x9a

should be

>>> data[20:24]

Yuri  Mar 22, 2024 
PDF Page 248
2nd paragraph

The book says "Python’s standard library has many date and time modules, including: datetime,
time, calendar, dateutil, and others." Actually dateutil is not part of Python's standard library - it's a third-party library.

Adam Dingle  Dec 15, 2023 
PDF Page 266
Table 13-2

"a" should be "%a" for the weekday abbrev row

O'Reilly Media
 
Jul 28, 2020 
ePub Page 268
Beginning of the section "Duck typing"

The sentence "Let’s use the same __init__() initializer for all three Quote classes now, but add two new functions" appears to assume that these three classes have already been introduced and discussed. But that is not the case.

Anonymous  Nov 19, 2020 
Printed Page 280
the paragraph below the mp.py output

The paragraph reads:

The Process() function spawned a new process and rand the do_this() function...

but the program doesn't have a do_this() function, it should refer to the whoami function

a couple of lines later it refers to the do_this function, again should be the whoami function

bruno carballo zama  Aug 28, 2020 
Printed Page 306
2nd paragraph

Example 16-1
Does not create villains.csv file on my computer, but creates a villains.txt file. I am using an iMac and macOS Big Sur, version 11.6. Python version 3.8.9.

I do not know if this is due to the line that contains:

with open('villains.txt', 'wt') as fout:

as shown in the book.

or if this should be a python script rather than in immediate mode as were the previous examples?

Glenn Travis  Oct 13, 2021 
Printed Page 306
2nd paragraph

I initially posted as unconfirmed. However I went back and based on what I was suspicious of, changed the line of code from :

villains.txt to villains.csv.

and also wrote it as a python script.

That successfully created the villains.csv file as per the example. I was able to open the .csv file with Macintosh Text Edit, BBEdit and Excel and it looked as shown in the book. The Excel file looked best.

This time the Pandas example worked exactly as shown in the book also.

The book should be changed to reflect this.


Example 16-1
Does not create villains.csv file on my computer, but creates a villains.txt file. I am using an iMac and macOS Big Sur, version 11.6. Python version 3.8.9.

I do not know if this is due to the line that contains:

with open('villains.txt', 'wt') as fout:

as shown in the book.

or if this should be a python script rather than in immediate mode as were the previous examples?

Glenn Travis  Oct 13, 2021 
Printed Page 331
First paragraph starting with "The following is..."

"`'w'` to write" should be "`'w'` to read and write for existing database" in the second line.

Yuri  Sep 28, 2020 
Printed Page 404
Line 22 of listing 18-14

This isn't as much an error in the code of listing 18-14 (iamovies.py) as a tip for getting it to work. When I tried to run it I got KeyErrors every time. After some debugging it turns out that the errors were due to missing descriptions in many of the entries in the archive (there is always a title and always an identifier). The best way to handle this, I found, was to replace 'doc["description"]' in line 22 with doc.get("description"), which returns None if there is no such key instead of a KeyError. Once I made this change the script worked as advertised.

Bruce Altner  Oct 30, 2021 
ePub Page 494, 495
2nd paragraph of "concurrent.futures" text, __main__

"The program takes an optional command_line argument of the number of workers to use, which defaults to 3."

if __name__ == '__main__':
workers = int(sys.argv[1])
values = list(range(1, 6)) # 1 .. 5
main(workers, values)
=====================================
First, the "#1..5" comment makes no sense.

More significantly, there is no default for "workers".
The relevant line could be changed to:
workers = sys.argv[1] if len(sys.argv) > 1 else 3


Gregory Sherman  Oct 05, 2022 
Printed Page 536
Last paragraph (in solution for 6.2)

Replace the "start" in last 2 lines with "number"

Sanjay S  Apr 26, 2020 
Printed Page 552
Top of the page

In Appendix D: Answers to Exercises

For chapter 11, exercise 11.5 is missing the answer. Previous page (551) ends with Answer for exercise 11.4, then next page (552) starts with Answer for exercise 11.6

Gio J  Sep 12, 2022 
Printed Page 578
punctuation attribute

In the punctuation entry of the string module attributes, it should read:
'!"#$%&\'()*+,-./:;<=>?@[\\]^_`{|}~'
but there are two strange things. (1) Near the end of this string, the backtick character is mistakenly written as a backslash, and (2) the font changes from this point onwards too, i.e., the final characters are written in the wrong font: {|}~

I am especially surprised about this, because a backtick and the font both appear correctly on page 74, when the string.punctuation is introduced.

Please take the code from page 74 for string.punctuation (which is correct) and use it on page 578, which has these two imperfections. Thanks!

Mark Daniel Ward  Oct 26, 2020 
ePub Page 612
json_rpcclient.py

When run under Python 3.10.0 on a Windows 10 PC with newly installed jsonrpcclient-4.0.2, it fails with:

...\jsonrpc_client.py", line 4, in <module>
response = request("...localhost:5000", "double", num=num)
TypeError: request_impure() got an unexpected keyword argument 'num'

Gregory Sherman  Oct 08, 2022 
ePub Page 817
"So far ..." text and example below

"So far, our examples have used integers, but floats work just fine:

>>> f = np.arange(2.0, 9.8, 0.3)"

The output includes 9.8, the ending value, which is NOT consistent with the integer examples above. However, if the ending value is changed to 10.1, that # does not appear in the output. I used numpy 1.22.4

Gregory Sherman  Oct 17, 2022