Errata

Automate the Boring Stuff with Python

Errata for Automate the Boring Stuff with 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
ePub Page https://www.safaribooksonline.com/library/view/automate-the-boring/9781457189906/ch09.html
Step 3: Walk the Directory Tree and Add to the ZIP File

https://www.safaribooksonline.com/library/view/automate-the-boring/9781457189906/ch09.html

Step 3: Walk the Directory Tree and Add to the ZIP File

In the Code snippet of there is a slash "/" after the variable name which should actually be an equals sign "=" for variable assignment


~~ERROR~~
for filename in filenames:
newBase / os.path.basename(folder) + '_'



**CORRECTION**
for filename in filenames:
newBase = os.path.basename(folder) + '_'

Brian Liceaga  Sep 21, 2017 
3 Functions
Python Programming Basics -> Functions -> Local Scopes Cannot Use Variables in Other Local Scopes

The example code in the book will throw the following error when executed:

Traceback (most recent call last):
File "./inception.py", line 21, in <module>
spam()
File "./inception.py", line 9, in spam
bacon()
UnboundLocalError: local variable 'bacon' referenced before assignment

This is due to the 'bacon' function being called upon before being defined. The affected code snippet looks as follows:

###
def spam():
eggs = 99
bacon()
print(eggs)
def bacon():
ham = 101
eggs = 0
spam()
###

This error can be prevented by putting the 'bacon' function declaration before the 'spam' function declaration, as follows:

###
def bacon():
ham = 101
eggs = 0
def spam():
eggs = 99
bacon()
print(eggs)
spam()
###

Kind regards,

P. Winkelmolen
Snow B.V.

Snow B.V.  Sep 27, 2017 
PDF Page 86
Example before the last paragraph of the page

>>>supplies = ['pens', 'staplers', 'flame-throwers', 'binders']
>>>for i in range(len(supplies)):
print('Index ' + str(i) + ' in supplies is: ' + supplies[i]) ### This should be indented.

Tewodros T Gebresilase  Sep 06, 2019 
108
Chapter 5 - The keys(), values(), and items() Methods

On https://learning.oreilly.com/library/view/automate-the-boring/9781457189906/ch05.html in the "The keys(), values(), and items() Methods" section.

```
>>> for k in spam.keys():
print(spam[k])

color
age
```

should be

```
>>> for k in spam.keys():
print(k)

color
age
```

Actually it's correct in the printed version but wrong on Safari Books Online.

David Jarosch  Mar 10, 2019 
PDF Page 206
Top of the page (before the title of the new project section)

The text reads:

Keep in mind that, just as with writing to files, write code will erase all existing contents of a ZIP file. If you want to simply add files to an existing ZIP file, pass 'a' as the second argument to zipfile.ZipFile() to open the ZIP file in the append mode.

Problem:
for clarity let me use ZIP Archive when referring to the actual .zip file and "ZIPed" file when referring to files stored in the ZIP Archive.

The first occurence of "ZIP file" confuses me, it seems that it's not referring to the actual ZIP Archive but to the file that is stored in it (ZIPed file).

The second and the third occurrencies though, refer to the ZIP Archive.

My understanding (but I am still learning) is that:
when the ZIP Archive is opened in "w" mode the .write() method overwrites a ZIPed file with the same name (if any) in the ZIP Archive (other contents stay untouched).
When the ZIP Archive is opened in "a" mode the file is appended into the ZIP Archive, even if there is already a file with the same name.

Am I correct?

Best regards

Pasquale Miceli  Dec 31, 2019 
Printed Page 284
2nd line from top

In the book, 2 URL's in the requests.get:

res = requests.get('...//google.com/search/?q=' '...//google.com/search/?q='
+ ' '.join(sys.argv[1:]))

It is correct in the downloadable file:

res = requests.get('...//pypi.org/search/?q=' + ' '.join(sys.argv[1:]))


John Podlasek  Feb 20, 2021 
Printed Page 287
2nd from bottom paragraph

Text states " ...(in a for loop)..." should be "...(in a while loop).

John Podlasek  Mar 01, 2021 
Printed Page 295
2nd section of interactive shell text input

Missing closing apostrophe in:
...browser.find_element_by_id('user_name)

John Podlasek  Mar 01, 2021 
Printed Page 325
paragraph before SUMMARY

Extraneous "s" in:

...and pie charts by calling openpyxl.charts.LineChart()...

should be ...openpyxl.chart.LineChart()...

John Podlasek  Mar 01, 2021 
Printed Page 355
Step 1: Find All PDF Files

If the practitioner correctly writes combinePdfs.py, the preceding section on encrypting PDFs will leave an encrypted PDF residing in the working directory, causing an error. You might want to note moving or deleting any encrypted file before writing or running combinePdfs.py.

John Podlasek  Mar 03, 2021 
Printed Page 359
midway in interactive shell

"Len(doc.paragraghs[1].runs)" returns "5" instead of "4". "some" is shown to be a separate run. Experimentation has shown that a copy of file demo.docx to, say demo1.docx to execute, WILL return a value of 4. Editing demo1 in Word: just back space over a character and retype will subsequently show an increase in the number of runs in Python interactive shell. A NEW Word file, "pristinely" written, will return correct length; subsequent edit with no real change will also increase the runs length count... and the locale of the run also modified.
Would it be necessary to have the source Word file in a Read Only(author is not bound by Read Only) mode to post for others to use in this exercise, saving to a new file(ie restyled.docx)?
If this is a python-docx bug, maybe the work around is to save a fresh copy of the source file(post editing), so that way unintended breaks in the runs are eliminated.





John Podlasek  Mar 04, 2021 
Printed Page 381
1st code block

Hi O'Reilly Team,

Reaching out with some information that may be helpful.

On page 381 of the print copy under the 'Sending Text Messages' section there is a Python block with code related to accessing Twilio's libraries. The code instructs readers to import TwilioRestClient from twilio.rest. This is erroneous code.

In Twilio's announcement here (https://www.twilio.com/docs/libraries/python/usage-guide) in version 6.x of the Python SDK TwilioRestClient module is deprecated. The new equivalent library is named Client. So the module import correction needed on this page is "from twilio.rest import Client"

Based on several posts to StackOverflow (like here https://stackoverflow.com/questions/41013556/importerror-cannot-import-name-twiliorestclient) this issue is roughly 2 years old.

-Eric Barnes

Eric Barnes  Jan 26, 2019