(Ebooks PDF) Download Real World Python A Hacker S Guide To Solving Problems With Code 1st Edition Lee Vaughan Full Chapters
(Ebooks PDF) Download Real World Python A Hacker S Guide To Solving Problems With Code 1st Edition Lee Vaughan Full Chapters
com
https://textbookfull.com/product/real-world-
python-a-hacker-s-guide-to-solving-problems-with-
code-1st-edition-lee-vaughan/
https://textbookfull.com/product/statistics-with-r-solving-problems-
using-real-world-data-1st-edition-jenine-k-harris/
textbookfull.com
https://textbookfull.com/product/optimization-in-the-real-world-
toward-solving-real-world-optimization-problems-1st-edition-katsuki-
fujisawa/
textbookfull.com
https://textbookfull.com/product/impractical-python-projects-playful-
programming-activities-to-make-you-smarter-1st-edition-lee-vaughan/
textbookfull.com
https://textbookfull.com/product/industrial-hygiene-control-of-
airborne-chemical-hazards-second-edition-william-popendorf-author/
textbookfull.com
Understanding Ethics and Responsibilities in a Globalizing
World 1st Edition Maria Cecilia Coutinho De Arruda
https://textbookfull.com/product/understanding-ethics-and-
responsibilities-in-a-globalizing-world-1st-edition-maria-cecilia-
coutinho-de-arruda/
textbookfull.com
https://textbookfull.com/product/emerging-and-traditional-
technologies-for-safe-healthy-and-quality-food-1st-edition-viktor-
nedovic/
textbookfull.com
https://textbookfull.com/product/attention-balance-and-coordination-
the-a-b-c-of-learning-success-second-edition-beuret/
textbookfull.com
https://textbookfull.com/product/japanese-robot-culture-performance-
imagination-and-modernity-1st-edition-yuji-sone-auth/
textbookfull.com
https://textbookfull.com/product/peacebuilding-and-the-arts-jolyon-
mitchell/
textbookfull.com
Management And Competition In The Nhs, Second Edition
Chris Ham
https://textbookfull.com/product/management-and-competition-in-the-
nhs-second-edition-chris-ham/
textbookfull.com
RE AL WORLD
PY THON
A H A C K E R ’ S G U I D E TO
S O L V I N G P R O B L E M S W ITH CODE
LEE VAUGHAN
REAL-WORLD PYTHON
REAL-WORLD
PYTHON
A Hacker’s Guide to
Solving Problems with Code
by Lee Vaughan
San Francisco
REAL-WORLD PYTHON. Copyright © 2021 by Lee Vaughan.
All rights reserved. No part of this work may be reproduced or transmitted in any form or by any means,
electronic or mechanical, including photocopying, recording, or by any information storage or retrieval
system, without the prior written permission of the copyright owner and the publisher.
The following images are reproduced with permission: Figure 3-3 from istockphoto.com; Figure 5-1 courtesy
of Lowell Observatory Archives; Figures 5-2, 6-2, 7-6, 7-7, 8-18, and 11-2 courtesy of Wikimedia Commons;
Figures 7-2, 7-9, 7-17, 8-20, and 11-1 courtesy of NASA; Figure 8-1 photo by Evan Clark; Figure 8-4 photo by
author; Figure 9-5 from pixelsquid.com; Figure 11-9 photo by Hannah Vaughan
For information on distribution, translations, or bulk sales, please contact No Starch Press, Inc. directly:
No Starch Press, Inc.
245 8th Street, San Francisco, CA 94103
phone: 1-415-863-9900; info@nostarch.com
www.nostarch.com
No Starch Press and the No Starch Press logo are registered trademarks of No Starch Press, Inc. Other prod-
uct and company names mentioned herein may be the trademarks of their respective owners. Rather than use
a trademark symbol with every occurrence of a trademarked name, we are using the names only in an editorial
fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark.
The information in this book is distributed on an “As Is” basis, without warranty. While every precaution
has been taken in the preparation of this work, neither the author nor No Starch Press, Inc. shall have any
liability to any person or entity with respect to any loss or damage caused or alleged to be caused directly or
indirectly by the information contained in it.
For my uncle, Kenneth P. Vaughan.
He brightened every room he entered.
About the Author
Lee Vaughan is a programmer, pop culture enthusiast, educator, and author
of Impractical Python Projects (No Starch Press, 2018). As an executive-level
scientist at ExxonMobil, he constructed and reviewed computer models,
developed and tested software, and trained geoscientists and engineers.
He wrote both Impractical Python Projects and Real-World Python to help
self-learners hone their Python skills and have fun doing it!
Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xvii
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xix
Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 315
CONTE NT S IN DE TA IL
ACKNOWLEDGMENTS xvii
INTRODUCTION xix
Who Should Read This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Why Python? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
What’s in This Book? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xx
Python Version, Platform, and IDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Installing Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxii
Running Python . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiv
Using a Virtual Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
Onward! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxv
1
SAVING SHIPWRECKED SAILORS WITH BAYES’ RULE 1
Bayes’ Rule . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Project #1: Search and Rescue . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
Installing the Python Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
The Bayes Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Playing the Game . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Challenge Project: Smarter Searches . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Challenge Project: Finding the Best Strategy with MCS . . . . . . . . . . . . . . . . . . . . . . . . 25
Challenge Project: Calculating the Probability of Detection . . . . . . . . . . . . . . . . . . . . . . 25
2
ATTRIBUTING AUTHORSHIP WITH STYLOMETRY 27
Project #2: The Hound, The War, and The Lost World . . . . . . . . . . . . . . . . . . . . . . . . . 28
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Installing NLTK . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
The Corpora . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
The Stylometry Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Practice Project: Hunting the Hound with Dispersion . . . . . . . . . . . . . . . . . . . . . . . . . . 48
Practice Project: Punctuation Heatmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Challenge Project: Fixing Frequency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3
SUMMARIZING SPEECHES WITH NATURAL
LANGUAGE PROCESSING 51
Project #3: I Have a Dream . . . to Summarize Speeches! . . . . . . . . . . . . . . . . . . . . . . 52
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Web Scraping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
The “I Have a Dream” Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Project #4: Summarizing Speeches with gensim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Installing gensim . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
The Make Your Bed Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
Project #5: Summarizing Text with Word Clouds . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
The Word Cloud and PIL Modules . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
The Word Cloud Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Fine-Tuning the Word Cloud . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Challenge Project: Game Night . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
Challenge Project: Summarizing Summaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Challenge Project: Summarizing a Novel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Challenge Project: It’s Not Just What You Say,
It’s How You Say It! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
4
SENDING SUPER-SECRET MESSAGES WITH A BOOK CIPHER 77
The One-Time Pad . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
The Rebecca Cipher . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
Project #6: The Digital Key to Rebecca . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
The Encryption Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Sending Messages . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Practice Project: Charting the Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Practice Project: Sending Secrets the WWII Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
5
FINDING PLUTO 95
Project #7: Replicating a Blink Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
The Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
The Blink Comparator Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Using the Blink Comparator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
Project #8: Detecting Astronomical Transients with Image Differencing . . . . . . . . . . . . 112
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
The Transient Detector Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Using the Transient Detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Practice Project: Plotting the Orbital Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
xii Contents in Detail
Practice Project: What’s the Difference? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
Challenge Project: Counting Stars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 120
6
WINNING THE MOON RACE WITH APOLLO 8 123
Understanding the Apollo 8 Mission . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
The Free Return Trajectory . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
The Three-Body Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Project #9: To the Moon with Apollo 8! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
Using the turtle Module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 127
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 131
The Apollo 8 Free Return Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Running the Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Practice Project: Simulating a Search Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Practice Project: Start Me Up! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 147
Practice Project: Shut Me Down! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 148
Challenge Project: True-Scale Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Challenge Project: The Real Apollo 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
7
SELECTING MARTIAN LANDING SITES 151
How to Land on Mars . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 152
The MOLA Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Project #10: Selecting Martian Landing Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 154
The Site Selector Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 171
Practice Project: Confirming That Drawings Become Part of an Image . . . . . . . . . . . . . 172
Practice Project: Extracting an Elevation Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
Practice Project: Plotting in 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Practice Project: Mixing Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 173
Challenge Project: Making It Three in a Row . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
Challenge Project: Wrapping Rectangles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 175
8
DETECTING DISTANT EXOPLANETS 177
Transit Photometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Project #11: Simulating an Exoplanet Transit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 179
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
The Transit Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 181
Experimenting with Transit Photometry . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Project #12: Imaging Exoplanets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 188
The Pixelator Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 189
Contents in Detail xiii
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 194
Practice Project: Detecting Alien Megastructures . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Practice Project: Detecting Asteroid Transits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 197
Practice Project: Incorporating Limb Darkening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Practice Project: Detecting Starspots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Practice Project: Detecting an Alien Armada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 200
Practice Project: Detecting a Planet with a Moon . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
Practice Project: Measuring the Length of an Exoplanet’s Day . . . . . . . . . . . . . . . . . . . 201
Challenge Project: Generating a Dynamic Light Curve . . . . . . . . . . . . . . . . . . . . . . . . 202
9
IDENTIFYING FRIEND OR FOE 203
Detecting Faces in Photographs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 204
Project #13: Programming a Robot Sentry Gun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
The Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 218
Detecting Faces from a Video Stream . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 221
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Practice Project: Blurring Faces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 222
Challenge Project: Detecting Cat Faces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 223
10
RESTRICTING ACCESS WITH FACE RECOGNITION 225
Recognizing Faces with Local Binary Pattern Histograms . . . . . . . . . . . . . . . . . . . . . . 226
The Face Recognition Flowchart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 226
Extracting Local Binary Pattern Histograms . . . . . . . . . . . . . . . . . . . . . . . . . 228
Project #14: Restricting Access to the Alien Artifact . . . . . . . . . . . . . . . . . . . . . . . . . . 231
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
Supporting Modules and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 231
The Video Capture Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 232
The Face Trainer Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 236
The Face Predictor Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 238
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 241
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 242
Challenge Project: Adding a Password and Video Capture . . . . . . . . . . . . . . . . . . . . 242
Challenge Project: Look-Alikes and Twins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
Challenge Project: Time Machine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 243
11
CREATING AN INTERACTIVE ZOMBIE ESCAPE MAP 245
Project #15: Visualizing Population Density with a Choropleth Map . . . . . . . . . . . . . . 246
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 247
The Python Data Analysis Library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 248
The bokeh and holoviews Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 249
Installing pandas, bokeh, and holoviews . . . . . . . . . . . . . . . . . . . . . . . . . . . 250
xiv Contents in Detail
Accessing the County, State, Unemployment, and Population Data . . . . . . . . . 250
Hacking holoviews . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 252
The Choropleth Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 254
Planning the Escape . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 262
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 266
Challenge Project: Mapping US Population Change . . . . . . . . . . . . . . . . . . . . . . . . . 266
12
ARE WE LIVING IN A COMPUTER SIMULATION? 269
Project #16: Life, the Universe, and Yertle’s Pond . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
The Pond Simulation Code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 270
Implications of the Pond Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 273
Measuring the Cost of Crossing the Lattice . . . . . . . . . . . . . . . . . . . . . . . . . 275
Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 277
The Strategy . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 278
Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Further Reading . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Moving On . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Challenge Project: Finding a Safe Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 279
Challenge Project: Here Comes the Sun . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 280
Challenge Project: Seeing Through a Dog’s Eyes . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Challenge Project: Customized Word Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
Challenge Project: Simplifying a Celebration Slideshow . . . . . . . . . . . . . . . . . . . . . . . 281
Challenge Project: What a Tangled Web We Weave . . . . . . . . . . . . . . . . . . . . . . . . 281
Challenge Project: Go Tell It on the Mountain . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 281
APPENDIX
PRACTICE PROJECT SOLUTIONS 283
Chapter 2: Attributing Authorship with Stylometry . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Hunting the Hound with Dispersion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 283
Punctuation Heatmap . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 284
Chapter 4: Sending Super-Secret Messages with a Book Cipher . . . . . . . . . . . . . . . . . 285
Charting the Characters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 285
Sending Secrets the WWII Way . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 286
Chapter 5: Finding Pluto . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
Plotting the Orbital Path . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 289
What’s the Difference? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 290
Chapter 6: Winning the Moon Race with Apollo 8 . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Simulating a Search Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 292
Start Me Up! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 293
Shut Me Down! . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 296
Chapter 7: Selecting Martian Landing Sites . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Confirming That Drawings Become Part of an Image . . . . . . . . . . . . . . . . . . 298
Extracting an Elevation Profile . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 298
Plotting in 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 299
Mixing Maps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 300
Chapter 8: Detecting Distant Exoplanets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Detecting Alien Megastructures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 304
Detecting Asteroid Transits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 305
Contents in Detail xv
Incorporating Limb Darkening . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 306
Detecting an Alien Armada . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 307
Detecting a Planet with a Moon . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 309
Measuring the Length of an Exoplanet’s Day . . . . . . . . . . . . . . . . . . . . . . . . 311
Chapter 9: Identifying Friend or Foe . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Blurring Faces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 312
Chapter 10: Restricting Access with Face Recognition . . . . . . . . . . . . . . . . . . . . . . . . 312
Challenge Project: Adding a Password and Video Capture . . . . . . . . . . . . . . 312
INDEX 315
xvi Contents in Detail
ACKNOWLEDGMENTS
Why Python?
Python is a high-level, interpretive, general-purpose programming language.
It’s free, highly interactive, and portable across all major platforms and micro-
controllers such as the Raspberry Pi. Python supports both functional and
object-oriented programming and can interact with code written in many
other programming languages, such as C++.
Because Python is accessible to beginners and useful to experts, it has
penetrated schools, universities, large corporations, financial institutions,
and most, if not all, fields of science. As a result, it’s now the most popular
language for machine learning, data science, and artificial intelligence
applications.
xx Introduction
cool display for advertising or promotional material. Gain experience
with BeautifulSoup, Requests, regex, NLTK, Collections, wordcloud, and
matplotlib.
Chapter 4: Sending Super-Secret Messages with a Book Cipher Share
unbreakable ciphers with your friends by digitally reproducing the one-
time pad approach used in Ken Follet’s best-selling spy novel, The Key to
Rebecca. Gain experience with the Collections module.
Chapter 5: Finding Pluto Reproduce the blink comparator device
used by Clyde Tombaugh to discover Pluto in 1930. Then use modern
computer vision techniques to automatically find and track subtle tran-
sients, such as comets and asteroids, moving against a starfield. Gain
experience with OpenCV and NumPy.
Chapter 6: Winning the Moon Race with Apollo 8 Take the gamble
and help America win the moon race with Apollo 8. Plot and execute
the clever free return flight path that convinced NASA to go to the moon
a year early and effectively killed the Soviet space program. Gain expe-
rience using the turtle module.
Chapter 7: Selecting Martian Landing Sites Scope out potential land-
ing sites for a Mars lander based on realistic mission objectives. Display
the candidate sites on a Mars map, along with a summary of site statis-
tics. Gain experience with OpenCV, the Python Imaging Library, NumPy,
and tkinter.
Chapter 8: Detecting Distant Exoplanets Simulate an exoplanet’s
passing before its sun, plot the resulting changes in relative brightness,
and estimate the diameter of the planet. Finish by simulating the direct
observation of an exoplanet by the new James Webb Space Telescope,
including estimating the length of the planet’s day. Use OpenCV, NumPy,
and matplotlib.
Chapter 9: Identifying Friend or Foe Program a robot sentry gun
to visually distinguish between Space Force Marines and evil mutants.
Gain experience with OpenCV, NumPy, playsound, pyttsxw, and datetime.
Chapter 10: Restricting Access with Face Recognition Restrict access
to a secure lab using face recognition. Use OpenCV, NumPy, playsound,
pyttsxw, and datetime.
Chapter 11: Creating an Interactive Zombie Escape Map Build a pop-
ulation density map to help the survivors in the TV show The Walking Dead
escape Atlanta for the safety of the American West. Gain experience
with pandas, bokeh, holoviews, and webbrowser.
Chapter 12: Are We Living in a Computer Simulation? Identify a way
for simulated beings—perhaps us—to find evidence that they’re living
in a computer simulation. Use turtle, statistics, and perf_counter.
Each chapter ends with at least one practice or challenge project. You
can find solutions to the practice projects in the appendix or online. These
aren’t the only solutions, or necessarily the best ones; you may come up with
better ones on your own.
Introduction xxi
When it comes to the challenge projects, however, you’re on your own.
It’s sink or swim, which is a great way to learn! My hope is that this book
motivates you to create new projects, so think of the challenge projects as
seeds for the fertile ground of your own imagination.
You can download all of the book’s code, including solutions to the
practice projects, from the book’s website at https://nostarch.com/real-world
-python/. You’ll also find the errata sheet there, along with any other updates.
It’s almost impossible to write a book like this without some initial errors.
If you see a problem, please pass it on to the publisher at errata@nostarch.com.
We’ll add any necessary corrections to the errata and include the fix in future
printings of the book, and you will gain eternal glory.
Installing Python
You can choose to install Python directly on your machine or through a
distribution. To install directly, find the installation instructions for your
operating system at https://www.python.org/downloads/. Linux and macOS
machines usually come with Python preinstalled, but you may want to upgrade
this installation. With each new Python release, some features are added and
some are deprecated, so I recommend upgrading if your version predates
Python v3.6.
The download button on the Python site (Figure 1) may install 32-bit
Python by default.
xxii Introduction
Figure 1: Downloads page for Python.org, with the “easy button” for the Windows platform
If you want the 64-bit version, scroll down to the listing of specific
releases (Figure 2) and click the link with the same version number.
Clicking the specific release will take you to the screen shown in
Figure 3. From here, click the 64-bit executable installer, which will launch
an installation wizard. Follow the wizard directions and take the default
suggestions.
Introduction xxiii
Random documents with unrelated
content Scribd suggests to you:
THE TRUTH ABOUT LUCK.
How often we hear some one say:
“My, but he’s lucky!” or “It’s better to be born lucky than rich.”
Boys and girls are too often in the habit of thinking that one of
their schoolmates are “lucky” because they always stand well in their
classes and frequently have spending money in their pockets.
It is not likely that “luck” had anything to do with it. They probably
stood well and were at the head of the class in school because they
studied and tried harder than the other scholars, and had money to
spend because they spent their time out of school hours in working
to earn it instead of at play.
Some years ago I happened to find myself near the terminal of
the great East River Bridge in New York City. Two little boys were
standing near one of the large iron posts crying their afternoon
papers. I tarried near them because I was waiting for a particular
car. One little fellow said to the other,—
“How many papers have you sold today, Tommie?”
“Nearly one hundred an’ fifty,” was Tommie’s quick reply.
“Honor bright?”
“Yes; honor bright.”
“Whoopee! but ain’t you in big luck, Tommie?”
“Luck!” exclaimed Tommie, wiping the perspiration from his brow.
“There ain’t no luck about it; I’ve just been everlastingly at it since
four o’clock this morning—that’s all!”
And that is the all of real success. Those who achieve success are
“everlastingly at” what they are trying to do. Tommie was right in
declining to have his hard and honest work cheapened by calling the
result of it luck.
“You are the luckiest chap I ever saw,” I once heard a little boy
about sixteen years say to another boy of about the same age.
The young folks themselves should take the lead in this matter. A
home is not merely a place with four walls where people meet to eat
and drink and sleep securely beneath a roof. Nay, boys and girls, a
house is reared to be a home—the center where a family may gather
into one; to be a serene retreat where the tenderest affections may
find rest; where love may have a dwelling place, and the amenities
of life gain ample scope; where parents and children may press one
another heart to heart; where sorrows and joys may be freely
shared in sacred confidence; in a word, where the great work of
training human beings for the duties of the present life, and the
perfection of another, may be begun and carried on.
There is one special reason for making much of the evenings at
home that young people are not likely to think of. Inevitably the
family circle will be broken up very soon. Perhaps not by death, but
most certainly by change. When Fred goes to college that is the
beginning of new ties and new associations, and the home privileges
can never be quite so complete to him again. The years of the
complete unity of the home are very few indeed. While these years
are passing, young people especially should make the most of them.
My dear boys and girls, get the benefit of these years; get their joys;
store up memories of home life, for they will be in future years the
most beautiful pictures of the heart. However some may sneer at it,
the memory of home and mother is a great power for righteousness.
It has saved many a person to God and native land and race.
* * * * *
A young woman of my acquaintance refused to carry home a
yeast cake, though it was needed at once for the family baking and
she was bound directly homeward. She said that she wasn’t a
delivery wagon, and so the yeast cake had to be sent to her home.
A great many foolish young people are so absorbingly regardful of
their trim appearance on the street that they will never under any
circumstances carry a basket or bundle, however much
inconvenience they may cause others by refusing to do so.
* * * * *
Now, it is not proper pride or self-respect which prompts people to
act as the young folks acted whom I have just referred to. It is
silliness which prompts them to act so. Any honest work is honorable
that is honorably done, and you will notice that young people of
good social position and strength of character are above such
pettiness. Only inferior people act that way. Superior people do not
act so, because they are well aware that they cannot be
compromised by doing straightforwardly, without fuss or apology,
whatever needs to be done. Yet, I admit, that it seems to be human
nature that whatever is distasteful or supposedly menial should be
done by somebody else. When young people, or old people for that
matter, are tempted to be foolish in such things they should
remember the lesson of humility that Christ taught his disciples,
when in that warm Oriental country, where only sandals are worn,
He performed the necessary service of washing the disciples’ feet.
For us to be above our business—for us to think ourselves too good
or too dainty to soil our hands with honest toil—for us to feel that it
is a lowering of our dignity to carry a bundle through the street, is to
prove by our conduct that we are not up to the level of our business,
that we are possessed of a great amount of false pride, and, in a
higher sense, it shows that we have a foolish and wicked distaste of
true service. There is nothing low, nothing degrading, nothing
disgraceful, in honest labor, in honest work of any kind, whether it
be to boil an egg properly, to sweep a floor well, to carry a bundle or
package through the streets, or bring a pail of water. In fact, if
somebody were to say that “chores” done or undone are the making
or the unmaking of boys and girls, it would be a homely way of
putting an important truth. Bringing up coal or bringing in wood,
weeding the garden bed, running errands, washing dishes, sewing
seams, dusting furniture, doing any odd jobs where there is need,
cheerfully, faithfully—these lead to the highway of greater
opportunities and are the usual avenues to the only manhood and
womanhood that is worth having. My young friends, the castle of
your noblest dream is built out of what lies nearest at hand. It is the
uncommonly good use of common things, the everyday
opportunities, that makes honored lives, and helps us, and helps us
to help others, along the sunroad. “He that is faithful in that which is
least is faithful also in much.” “Pride goeth before destruction, and a
haughty spirit before a fall.”
THANKSGIVING AT PINEY GROVE.
The people of the Piney Grove settlement, both white and black,
had been free for nearly a generation. The whites had been freed
from the curse of being slave-holders, and the blacks had been freed
from the curse of being held in bondage. But never in the history of
this little town, in the very heart of the so-called “Black Belt” of
Georgia, had the people known anything about the proper
observance of Thanksgiving Day until 189—. And in that year the
revolution was brought about by a young colored woman named
Grace Wilkins.
Grace Wilkins was the only daughter of Solomon and Amanda
Wilkins. Solomon and his wife were farmers—plain, simple, ordinary
country folk. Amanda was literally her husband’s helpmeet. She went
along with him every morning to the field, and, in season, chopped
as much wood, picked as much cotton, hoed as much corn, pulled as
much fodder, and plowed as much as her husband did. Up to her
fourteenth year Grace had been reared on a farm, and had learned
to do all the things that any farmer’s child has to do—such as
milking cows, feeding hogs and chickens, hoeing cotton and corn,
picking cotton, pulling fodder and the like. In her fourteenth year,
acting upon the advice of an uneducated colored preacher, her
parents sent Grace away from home to attend one of the great
normal and industrial institutes for the training of the black boys and
girls of the South.
Grace Before Going to School.
At first her mother and father were filled with forebodings. It was
the first time that they had ever allowed their daughter to be away
from them, and they missed her so much and longed for her so
constantly that they thought that they had made a mistake in
sending her off to “boardin’ school.” Ignorant and superstitious
neighbors, though they knew as little about such matters as did
Solomon and Amanda, were loud in saying that “Sol” and “Mandy”
would live to regret the step they had taken in sending Grace away
from home. The only rays of sunshine that came in to brighten these
periods of mental unrest and gloom on the part of Mr. and Mrs.
Wilkins were found in the letters which they received regularly from
their daughter. Grace invariably informed her parents, whenever she
wrote, that she was “well an’ doin’ well.” Thus reassured from time
to time, Solomon and Amanda managed somehow to undergo the
terrible strain of having their daughter absent from them for eight
months. But meantime they were firmly of the opinion that, once
they got their hands on her again, they would never allow Grace to
return to school.
With glad and thankful hearts Mr. and Mrs. Wilkins joyously
embraced their daughter when she came home at the close of her
first year in school. With keen and genuine interest, they listened to
her wonderful accounts of the great school and of the great man at
the head of it. Grace dressed differently and talked differently; and
her mother said, speaking one day in confidence to her husband
shortly after Grace’s return, “Dat gal’s sho got a new walk on her!”
Grace Wilkins brought back a toothbrush with her from school.
That was something which she had never had before. She used that
toothbrush every morning and night. That was something that she
had never done before. She was now careful to keep her hair well
combed every day. That was something that she had been
accustomed to do on Sundays only or on special occasions. She
washed her face two or three times a day now, as her mother and
father noticed. Before she went to school she had been in the habit
of giving her face, as the old people say, “a lick and a promise” early
each morning. Besides, Grace kept the house cleaner than she had
kept it before. She brought home with her a brand new Bible which
she read regularly at home and always carried to church and Sunday
school. She also had a song book called “Jubilee Songs and
Plantation Melodies,” and it gladdened the hearts of the good “old
folks at home” to hear their daughter sing from a book some of the
very songs that they had sung all their lifetime and which were so
dear to them.
All these things and others made a deep and abiding impression
upon Solomon and his wife. And finding that withal their daughter
was just as loving and kind as she had been before, and that she
was just as industrious and faithful as formerly, Mr. and Mrs. Wilkins
were not long in deciding that their daughter should go back to that
school another year, and that they would work hard and stint
themselves in order that they might keep her there until she had
finished the normal course.
So back to school Grace Wilkins went—that year, and the next
year, and the next. It was the proudest day in Solomon’s and
Amanda’s lives when they sat in the magnificent chapel of the school
and heard their daughter read her graduation essay on “The Gospel
of Service.” Glad tears welled up in their eyes when they heard the
principal call their daughter’s name, and then saw Grace step up to
receive her certificate of graduation.
Coming back to Piney Grove to live, “Miss Gracie”—everybody
called her that after graduation—established a little school which she
called “The Piney Grove Academy.” It was the first public school for
colored children ever opened within the corporate limits of the little
village. Before that the schools were district schools or county
schools, which were taught about in different places for only three or
four months in the year, mainly during the summer. Miss Gracie
began her school the first day of October. By special arrangement
she used the first three months for the public term allowed by the
state, and supplemented that with a five-months term, for which the
pupils were required to pay fifty cents each per month. The plan
worked well, the parents joining in heartily in the movement, and
the Piney Grove Academy soon became the model school for the
surrounding counties.
Grace’s Graduation.
Among other things Miss Gracie had learned at school what was
the import of our national Thanksgiving Day. At the opening of the
second year of the Piney Grove Academy she decided that she would
inaugurate an annual Thanksgiving service. Accordingly on the
opening day of the second year Miss Gracie informed the pupils of
her plan, and told them that she would begin the very next day to
prepare a suitable program for the exercises. Afterwards Miss Gracie
secured the cooperation of the village pastor—the same man who
had been instrumental in having her parents send her away to
school. Through him she was permitted to talk to the people at the
church two or three times about the proposed celebration. She was
careful to tell them that the Thanksgiving festival was meant
specially to be a home festival in addition to being a time for the
people to come together in their accustomed places of worship to
thank God for the blessings of the year. She urged them, therefore,
as far as they were able without going to unnecessary expense, to
have family dinners and bring together at one time and in one place
as many members of the family as possible. She explained to them
how this might be done successfully and economically, and with
pleasure and profit to all concerned. She also urged them to be
planning beforehand so that nothing might prevent their attending
church Thanksgiving Day morning. She was going to hold the
exercises in the church, because her little school was not large
enough to furnish an assembly hall for the people who would be
likely to be present.
On Thanksgiving Day nearly everybody in town went to the
exercises. Many white people attended, including the county school
commissioner and the school trustees. It was the first Thanksgiving
service that any of them had ever witnessed.
The program was made up, for the most part, of choice selections
from negro authors, composers, orators, and so forth. A selection
from Frederick Douglass on “Patriotism” was declaimed; one from
Booker T. Washington’s Atlanta Exposition speech was also delivered.
Paul Laurence Dunbar’s poem entitled “Signs of the Times” (a
Thanksgiving poem) was read by one of the pupils, and also “The
Party,” another of Dunbar’s pieces, was rendered. “The Negro
National Hymn,” words by James W. Johnson and music by his
brother, Rosamond Johnson, was sung by a chorus of fifty voices. At
the opening of the service the president’s Thanksgiving proclamation
was read and appropriate remarks were made by Miss Wilkins. The
closing remarks were made by the Rev. John Jones, the village
pastor. The remarks of Mr. Jones were in the congratulatory mood.
He was naturally proud of Miss Gracie’s achievements, because he
had had something to do with putting her on the road to an
education. He spoke of the teacher as the leaven that was leavening
the whole lump, and the applause which followed the statement
showed plainly the high esteem in which the teacher was held by all
the people. Everyone enjoyed the service. None of the villagers had
ever seen anything like it before. After singing “America” all of them
went away happy, many of them, in obedience to Miss Gracie’s
previous counsel, going home to eat for the first time, well knowing
what they were doing, a Thanksgiving dinner.
At the home of Miss Wilkins there was an excellent spread of
’possum, potatoes, rice, chicken, pickles, macaroni, bread, a
precious Thanksgiving turkey, and the inevitable mincemeat pie.
Besides Miss Gracie, there sat at the table that day her parents, Mr.
and Mrs. Solomon Wilkins, John and Joseph Wilkins, brothers of
Solomon who had come from a distance, Mary Andrews, a sister of
Mrs. Wilkins, who also came from a distance, Grandma Wilkins,
Grandma and Grandpa Andrews, the Rev. John Jones, his wife, his
daughter, and his only son, Jasper Jones.
Jasper had gone to school at T—— one year after Gracie went,
and, of course, was one year later in finishing the course there. On
this Thanksgiving Day, nevertheless, he had been out of school long
enough to have successfully established himself in the business of
poultry raising and dairying.
Just before the dinner party was dismissed the Rev. Mr. Jones
arose and said:
“There is another little ceremony you’all is invited to witness befo’
you go out to see the baseball game. I am authorized by these
credentials which I hol’ in my hands to unite in the holy bonds of
matrimony Miss Grace Wilkins and Mr. Jasper Jones. If there is no
objection, these two persons will please stan’ up, an’ I’ll tie the
knot.”
Of course there were no objections. The knot was tied. And when
the villagers learned of the occurrence not long afterwards they had
additional reason for believing that they were right when they voted
that Piney Grove had never seen the like of such a Thanksgiving
Day, and that Miss Gracie Wilkins was one of the best women in all
the world.
THE LOUD GIRL.
I do not know of a more sorrowful spectacle than that of a girl
who is loud in her dress, loud in her manners, and loud in her
speech. It is a great mistake for a girl to suppose that this loudness
will be mistaken by her friends and acquaintances for smartness.
The desire to be regarded as bright and witty has led many a girl
into the folly of being loud in her manners. She often cherishes the
illusion that the attention such manners attract is combined with
admiration, when the truth is that those who witness her strange
conduct are simply wondering how it is possible for her to throw to
the winds that charm of all girlhood—modesty.
Blab-Mouthed and Noisy.
One afternoon not long ago I saw a group of girls of the loud
type. They came into the street car in which I was sitting. They all
wore boys’ hats. One wore a vivid red jacket with brass buttons, and
another had on a brass belt. A third one had on a most conspicuous
plaid skirt. This third one had a box of bonbons, and when the three
were seated she opened the box and offered it to her companions,
saying as she did so, in a voice loud enough and shrill enough to be
heard in every part of the car:
“It’s my treat; have some, chums!”
Upon this invitation one of the
girls dived down into the box like a
hungry bear, and held up a piece of
the candy in triumph and then
dashed it into her mouth with a
great guffaw. “O, Mame!” said one
of the girls, “if you ain’t just horrid
to go and take the very piece I
wanted!”
“Mame” laughed and, taking the
candy from her mouth, offered it to
the other girl, saying as she did so:
“Well, here it is, Lulu!”
“Lulu” struck the candy from
“Mame’s” hand, and it flew across
the aisle into the lap of a lady sitting
opposite the girls. This set all three
of the girls to giggling and tittering,
and they seemed in danger of
convulsions when the owner of the
box of candy let it fall and a part of
the candy rolled out on the floor.
The conductor came forward and
picked up the box and candy and
handed them to the owner. She
giggled out her thanks, and “Lulu”
Modest and Quiet. said: “Why didn’t you give him a
gumdrop for his trouble?”
This seemed to impress the other girls as a most brilliant
witticism, and they fell to tittering violently over it.
Presently a gentleman came in and stumbled slightly over the feet
of one of the girls thrust out into the aisle.
“I beg your pardon,” said the gentleman, as he lifted his hat,
whereupon the three girls grinned and giggled and giggled and
grinned immoderately, and one of them said:
“Roxy, you had better ride out on the platform, where there is
more room for your feet!”
“Roxy” then struck “Lulu” for making this speech. “Lulu” pretended
to be much offended and flung herself over to the other side of the
car, where she made a grimace at the other girls.
The conduct of these girls during the half hour that they were on
the car was such as caused every father and mother who saw them
to regard them with pity. The loud girl, my dear readers, is always
an object of pity. She should be a sorry object for her own
contemplation. An old writer has said: “You little know what you
have done when you have first broken the bounds of modesty; you
have set open the door of your fancy to the devil, so that he can
represent the same sinful pleasure to you anew.”
Now, the loud girl may be entirely innocent of any actual wrong-
doing, but she is regarded with dislike, distrust, and even disdain, by
the better class of people. She acquires a reputation for rudeness
and coarseness, and the people of refinement will not associate with
her. Her character suffers, no matter how innocent she may be of
any intention of doing wrong. Delicacy, modesty, is the certain sign
of sweetness, purity and gentleness of character, just as indelicacy is
the certain sign of a lack of these beautiful traits.
THE ROWDY BOY.
You can tell him wherever you see him. There are certain marks or
appearances which he carries about with him and which are never
absent. For one thing you will find him with a cigarette stuck in his
mouth, and a cigarette is one of the deadliest poisons in the world
for boy or man. He wears his hat on the side or cocked back on his
head. Frequently he stuffs both hands in his trousers’ pockets. He
doesn’t attend school regularly; sometimes he starts for school and
ends at the bathing pond or the baseball park. He is late at Sunday
school, if he goes at all, and he stands ’round on the outside at
church while the service is going on inside. He steals rides on trains
and on trolley cars, and on passing vehicles of all descriptions. He is
saucy and impudent to older people, and is always ready and willing
to quarrel or fight with his mates. He is what the boys call a “bully.”
The loud girl and the rowdy boy are two things of which we have
seen enough in this world. They are things; they are hardly worth
the dignity of being called human beings.
I saw one of these rowdy boys in his own home not a great while
ago. His mother said to him:
“Johnnie, you must always take off your hat whenever you come
into the house.”
“Good gracious alive,” he said, “I can’t do anything right. What is
the use of grabbing off your hat every time you come into your own
house?”
He Stuffed Both Hands in His Trousers’ Pocket.
His mother looked sad, but said nothing. Presently she discovered
that her little boy had brought some mud into the house on his
shoes. In her sweetest tones she said:
“Johnnie, you must go to the door and wipe your feet now. See
how you are tracking up the floor there!”
“Well,” said the rowdy boy with a snarl, “can’t the old floor be
scoured? You must think this old house is gold.”
Now, I am a preacher, boys, and, being a preacher, of course I am
what is called a “man of peace,” but I tell you that that was one time
I came pretty near wishing that I wasn’t a preacher so that I might
have given that boy what he deserved. I was sorry, for the time
being, that he wasn’t my son. No manly little boy will ever talk to his
mother in any such way. I suppose that boy thought it made him
appear to be a very important personage, but he was very much
mistaken. Don’t be rowdy, boys; don’t be rough; don’t be rude. You
were made for better things.
HONESTY.
Early in the morning two little boys came to the market place.
They arranged their little stands and spread out their wares, and sat
down to wait for customers. One sold watermelons and fruit, and the
other sold fish and oysters. The hours passed on and both were
doing well. By-and-by Sammie had only one melon left on his stand.
A gentleman came along and said:
“What a fine, large melon! I think I will buy that one. What do you
ask for it, my boy?”
“How Much for the Melon?”