Updates and Errata - First printing
This page is broken into two parts, Updates and Errata. Updates address issues that affect whether your code will run or not. Errata refer to minor issues such as typos, and errors in grayed-out code that probably won’t affect the code you’re entering.
Code that produces warnings but still runs correctly is noted under Errata, as this is a fairly common occurrence and the code often still works for a long time while producing warnings.
If you find an error in the book that's not listed here, or can’t get something to work, please let me know.
Updates
Chapter 16
On Windows, the calls to path.read_text() should all have an encoding='utf-8' argument. On page 330, that would look like this:
path = Path('weather_data/sitka_weather_07-2021_simple.csv')
lines = path.read_text(encoding='utf-8').splitlines()
This also affects the calls to path.read_text() on pages 339 and 343. There are a few other grayed-out references to path.read_text() that should include this argument, but that shouldn't affect the code you're entering. Those are on pages 332, 334, 336, 339, 345, and 348.
Chapter 20
The second half of Chapter 20, starting on page 445, focuses on the process of deploying Learning Log to the hosting company Platform.sh. That company has rebranded as Upsun, and they've changed their approach to deployment somewhat.
Fully up-to-date instructions for deploying Learning Log are posted on the Deploying Django page. If anything in these instructions is not working for you, please don't hesitate to reach out.
Errata
Chapter 6
The output at the bottom of page 95 should say position, not x-position:
Chapter 9
On page 167, the docstring for the __init__() method in electric_car.py should have triple quotes on both ends:
Chapter 10
On page 200, Exercise 10-7 should read "Wrap your code from Exercise 10-6 in a while loop..."
Also, Exercise 10-9 should refer to Exercise 10-8.
Chapter 15
Matplotlib has a number of predefined styles that you can choose from. The book uses the seaborn style, which was base on a style from the Seaborn plotting library. The default style of the Seaborn library has diverged from Matplotlib's seaborn style, so they are changing the name of this style to make that clear. (If you're curious to read more about this, see "seaborn styles renamed" in the Matplotlib documentation page API Changes for 3.6.0.)
If you use seaborn as the book does, you'll see a MatplotlibDeprecationWarning. This won't prevent your code from running, and it won't affect the style of your output.
To avoid seeing this warning, use seaborn-v0_8 wherever you see seaborn in the book's code. The code should look like this:
Chapter 16
As noted above for Chapter 15, use seaborn-v0_8 wherever you see seaborn.
Also on page 351, the line that starts the for loop over all_eq_dicts is missing. This line was shown in earlier listings, but was left out on this page. The listing on page 351 should look like this:
--snip--
mags, lons, lats, eq_titles = [], [], [], []
for eq_dict in all_eq_dicts:
mag = eq_dict['properties']['mag']
lon = eq_dict['geometry']['coordinates'][0]
lat = eq_dict['geometry']['coordinates'][1]
eq_title = eq_dict['properties']['title']
mags.append(mag)
lons.append(lon)
lats.append(lat)
eq_titles.append(eq_title)
title = 'Global Earthquakes'
fig = px.scatter_geo(lat=lats, lon=lons, size=mags, title=title,
--snip--
projection='natural earth',
hover_name=eq_titles,
)
fig.show()
Chapter 17
On page 370, the code that starts the for loop should go through index 30, not 5:
submission_dicts = []
for submission_id in submission_ids[:30]:
# Make a new API call for each submission.
...
Chapter 18
On page 391, the path to the index.html template should read:
On page 399, the listing for topics.html has an extra closing tag </li>. It should look like this:
{% for topic in topics %}
<li>
<a href="{% url 'learning_logs:topic' topic.id %}">
{{ topic.text }}</a>
</li>
...
Chapter 19
On page 416, the sentence
Make a new urls.py file in the directory ll_project/accounts/ and add the following...
should instead read:
Make a new urls.py file in the directory learning_log/accounts/ and add the following...
On page 417 under The login Template the path to the accounts/ directory should be learning_log/accounts/, not ll_project/accounts/. The full path to the login.html template should be: learning_log/accounts/templates/registration/login.html.
Also on page 417, the word Settting should only have two Ts.
On page 425, in the grayed out code for models.py, the text attribute should be lowercase: