Skip to content

Commit 0672e50

Browse files
committed
Update the HTML Book
1 parent 9edfb7e commit 0672e50

20 files changed

+112
-77
lines changed

book3/zips/html.zip

1.26 KB
Binary file not shown.

html3/01-intro.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,11 @@
157157
div.columns{display: flex; gap: min(4vw, 1.5em);}
158158
div.column{flex: auto; overflow-x: auto;}
159159
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
160-
ul.task-list{list-style: none;}
160+
/* The extra [class] is a hack that increases specificity enough to
161+
override a similar rule in reveal.js */
162+
ul.task-list[class]{list-style: none;}
161163
ul.task-list li input[type="checkbox"] {
164+
font-size: inherit;
162165
width: 0.8em;
163166
margin: 0 0.8em 0.2em -1.6em;
164167
vertical-align: middle;

html3/02-variables.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/03-conditional.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/04-functions.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/05-iterations.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/06-strings.php

+26-51
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;
@@ -506,55 +509,36 @@ class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a></p>
506509
<p><a
507510
href="https://docs.python.org/library/stdtypes.html#string-methods"
508511
class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a>.</p>
509-
<h2 id="format-operator">Format operator</h2>
510-
<p> </p>
511-
<p>The <em>format operator</em>, <code>%</code> allows us to construct
512-
strings, replacing parts of the strings with the data stored in
513-
variables. When applied to integers, <code>%</code> is the modulus
514-
operator. But when the first operand is a string, <code>%</code> is the
515-
format operator.</p>
516-
<p></p>
517-
<p>The first operand is the <em>format string</em>, which contains one
518-
or more <em>format sequences</em> that specify how the second operand is
519-
formatted. The result is a string.</p>
512+
<h2 id="formatted-string-literals">Formatted String Literals</h2>
520513
<p></p>
521-
<p>For example, the format sequence <code>%d</code> means that the
522-
second operand should be formatted as an integer (“d” stands for
523-
“decimal”):</p>
514+
<p>A formatted string literal (often referred to simply as an f-string)
515+
allows Python expressions to be used within string literals. This is
516+
accomplished by prepending an <code>f</code> to the string literal and
517+
enclosing expressions in curly braces <code>{}</code>.</p>
518+
<p>For example, wrapping a variable name in curly braces inside an
519+
f-string will cause it to be replaced by its value:</p>
524520
<pre class="python"><code>&gt;&gt;&gt; camels = 42
525-
&gt;&gt;&gt; &#39;%d&#39; % camels
521+
&gt;&gt;&gt; f&#39;{camels}&#39;
526522
&#39;42&#39;</code></pre>
527523
<p>The result is the string ‘42’, which is not to be confused with the
528524
integer value 42.</p>
529-
<p>A format sequence can appear anywhere in the string, so you can embed
530-
a value in a sentence:</p>
525+
<p>An expression can appear anywhere in the string, so you can embed a
526+
value in a sentence:</p>
531527
<pre class="python"><code>&gt;&gt;&gt; camels = 42
532-
&gt;&gt;&gt; &#39;I have spotted %d camels.&#39; % camels
528+
&gt;&gt;&gt; f&#39;I have spotted {camels} camels.&#39;
533529
&#39;I have spotted 42 camels.&#39;</code></pre>
534-
<p>If there is more than one format sequence in the string, the second
535-
argument has to be a tuple<a href="#fn1" class="footnote-ref"
536-
id="fnref1" role="doc-noteref"><sup>1</sup></a>. Each format sequence is
537-
matched with an element of the tuple, in order.</p>
538-
<p>The following example uses <code>%d</code> to format an integer,
539-
<code>%g</code> to format a floating-point number (don’t ask why), and
540-
<code>%s</code> to format a string:</p>
541-
<pre class="python"><code>&gt;&gt;&gt; &#39;In %d years I have spotted %g %s.&#39; % (3, 0.1, &#39;camels&#39;)
530+
<p>Several expressions can be included within a single string literal in
531+
order to create more complex strings.</p>
532+
<pre class="python"><code>&gt;&gt;&gt; years = 3
533+
&gt;&gt;&gt; count = .1
534+
&gt;&gt;&gt; species = &#39;camels&#39;
535+
&gt;&gt;&gt; f&#39;In {years} years I have spotted {count} {species}.&#39;
542536
&#39;In 3 years I have spotted 0.1 camels.&#39;</code></pre>
543-
<p>The number of elements in the tuple must match the number of format
544-
sequences in the string. The types of the elements also must match the
545-
format sequences:</p>
546-
<p> </p>
547-
<pre class="python"><code>&gt;&gt;&gt; &#39;%d %d %d&#39; % (1, 2)
548-
TypeError: not enough arguments for format string
549-
&gt;&gt;&gt; &#39;%d&#39; % &#39;dollars&#39;
550-
TypeError: %d format: a number is required, not str</code></pre>
551-
<p>In the first example, there aren’t enough elements; in the second,
552-
the element is the wrong type.</p>
553-
<p>The format operator is powerful, but it can be difficult to use. You
554-
can read more about it at</p>
537+
<p>Formatted string literals are powerful, and they can do even more
538+
than is covered here. You can read more about them at</p>
555539
<p><a
556-
href="https://docs.python.org/library/stdtypes.html#printf-style-string-formatting"
557-
class="uri">https://docs.python.org/library/stdtypes.html#printf-style-string-formatting</a>.</p>
540+
href="https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals"
541+
class="uri">https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals</a>.</p>
558542
<h2 id="debugging">Debugging</h2>
559543
<p></p>
560544
<p>A skill that you should cultivate as you program is always asking
@@ -684,7 +668,7 @@ class="uri">https://docs.python.org/library/stdtypes.html#printf-style-string-fo
684668
<p> </p>
685669
<p><strong>Exercise 6: Read the documentation of the string methods at
686670
<a href="https://docs.python.org/library/stdtypes.html#string-methods"
687-
class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a>
671+
class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a>.
688672
You might want to experiment with some of them to make sure you
689673
understand how they work. <code>strip</code> and <code>replace</code>
690674
are particularly useful.</strong></p>
@@ -693,15 +677,6 @@ class="uri">https://docs.python.org/library/stdtypes.html#string-methods</a>
693677
indicate optional arguments. So <code>sub</code> is required, but
694678
<code>start</code> is optional, and if you include <code>start</code>,
695679
then <code>end</code> is optional.</strong></p>
696-
<aside id="footnotes" class="footnotes footnotes-end-of-document"
697-
role="doc-endnotes">
698-
<hr />
699-
<ol>
700-
<li id="fn1"><p>A tuple is a sequence of comma-separated values inside a
701-
pair of parenthesis. We will cover tuples in Chapter 10<a href="#fnref1"
702-
class="footnote-back" role="doc-backlink">↩︎</a></p></li>
703-
</ol>
704-
</aside>
705680
</body>
706681
</html>
707682
<?php if ( file_exists("../bookfoot.php") ) {

html3/07-files.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/08-lists.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;
@@ -701,7 +704,7 @@ class="math inline"><em>n</em></span> is the length of the list. Each
701704
<li><p>Lists, <code>split</code>, and files</p>
702705
<p>When we read and parse files, there are many opportunities to
703706
encounter input that can crash our program so it is a good idea to
704-
revisit the <em>guardian</em> pattern when it comes writing programs
707+
revisit the <em>guardian</em> pattern when it comes to writing programs
705708
that read through a file and look for a “needle in the haystack”.</p>
706709
<p>Let’s revisit our program that is looking for the day of the week on
707710
the from lines of our file:</p>

html3/09-dictionaries.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/10-tuples.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/11-regex.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/12-network.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/13-web.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/14-objects.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;

html3/15-database.php

+15-7
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;
@@ -801,9 +804,9 @@ class="uri">http://en.wikipedia.org/wiki/Relational_model</a></p>
801804
cur = conn.cursor()
802805

803806
cur.execute(&#39;&#39;&#39;CREATE TABLE IF NOT EXISTS People
804-
(id INTEGER PRIMARY KEY, name TEXT UNIQUE, retrieved INTEGER)&#39;&#39;&#39;)
807+
(id INTEGER PRIMARY KEY, name TEXT UNIQUE, retrieved INTEGER)&#39;&#39;&#39;)
805808
cur.execute(&#39;&#39;&#39;CREATE TABLE IF NOT EXISTS Follows
806-
(from_id INTEGER, to_id INTEGER, UNIQUE(from_id, to_id))&#39;&#39;&#39;)
809+
(from_id INTEGER, to_id INTEGER, UNIQUE(from_id, to_id))&#39;&#39;&#39;)
807810

808811
# Ignore SSL certificate errors
809812
ctx = ssl.create_default_context()
@@ -814,7 +817,9 @@ class="uri">http://en.wikipedia.org/wiki/Relational_model</a></p>
814817
acct = input(&#39;Enter a Twitter account, or quit: &#39;)
815818
if (acct == &#39;quit&#39;): break
816819
if (len(acct) &lt; 1):
817-
cur.execute(&#39;SELECT id, name FROM People WHERE retrieved=0 LIMIT 1&#39;)
820+
cur.execute(
821+
&#39;SELECT id, name FROM People WHERE retrieved=0 LIMIT 1&#39;
822+
)
818823
try:
819824
(id, acct) = cur.fetchone()
820825
except:
@@ -834,7 +839,8 @@ class="uri">http://en.wikipedia.org/wiki/Relational_model</a></p>
834839
continue
835840
id = cur.lastrowid
836841

837-
url = twurl.augment(TWITTER_URL, {&#39;screen_name&#39;: acct, &#39;count&#39;: &#39;100&#39;})
842+
url = twurl.augment(TWITTER_URL,
843+
{&#39;screen_name&#39;: acct, &#39;count&#39;: &#39;100&#39;})
838844
print(&#39;Retrieving account&#39;, acct)
839845
try:
840846
connection = urllib.request.urlopen(url, context=ctx)
@@ -991,8 +997,10 @@ class="uri">http://en.wikipedia.org/wiki/Relational_model</a></p>
991997
<p>Once we know the key value for both the Twitter user and the friend
992998
in the JSON, it is a simple matter to insert the two numbers into the
993999
<code>Follows</code> table with the following code:</p>
994-
<pre class="python"><code>cur.execute(&#39;INSERT OR IGNORE INTO Follows (from_id, to_id) VALUES (?, ?)&#39;,
995-
(id, friend_id) )</code></pre>
1000+
<pre class="python"><code>cur.execute(
1001+
&#39;INSERT OR IGNORE INTO Follows (from_id, to_id) VALUES (?, ?)&#39;,
1002+
(id, friend_id)
1003+
)</code></pre>
9961004
<p>Notice that we let the database take care of keeping us from
9971005
“double-inserting” a relationship by creating the table with a
9981006
uniqueness constraint and then adding <code>OR IGNORE</code> to our

html3/16-viz.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;
@@ -423,7 +426,7 @@ class="uri">http://d3js.org/</a> to produce the visualization
423426
was called <em>gmane</em> - the service has since been shut down and for
424427
the purposes of this course, a partial archive has been kept at <a
425428
href="http://mbox.dr-chuck.net">http://mbox.dr-chuck.net</a>. The gmane
426-
service was very popular with open source projects because it provides a
429+
service was very popular with open source projects because it provided a
427430
nice searchable archive of their email activity.</p>
428431
<p><a
429432
href="http://mbox.dr-chuck.net/export.php">http://mbox.dr-chuck.net/export.php</a></p>

html3/A0-preface.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,11 @@
156156
div.columns{display: flex; gap: min(4vw, 1.5em);}
157157
div.column{flex: auto; overflow-x: auto;}
158158
div.hanging-indent{margin-left: 1.5em; text-indent: -1.5em;}
159-
ul.task-list{list-style: none;}
159+
/* The extra [class] is a hack that increases specificity enough to
160+
override a similar rule in reveal.js */
161+
ul.task-list[class]{list-style: none;}
160162
ul.task-list li input[type="checkbox"] {
163+
font-size: inherit;
161164
width: 0.8em;
162165
margin: 0 0.8em 0.2em -1.6em;
163166
vertical-align: middle;
@@ -174,6 +177,7 @@
174177
Cover Design: Aimee Andrion</code></pre>
175178
<h2 id="printing-history">Printing History</h2>
176179
<ul>
180+
<li>2023-Jun-29 Many errata included</li>
177181
<li>2016-Jul-05 First Complete Python 3.0 version</li>
178182
<li>2015-Dec-20 Initial Python 3.0 rough conversion</li>
179183
</ul>

0 commit comments

Comments
 (0)