:
(colon), creating functions, 61–62
avoid using with True
/False
, 31
create strings with single-quotes vs., 29
escaping inside strings, 34–36
prompt and pass, 47
>=
(greater-than-equal) operator, 16–17, 97
+=
(increment by) operator, 69–70, 105
<=
(less-than-equal) operator, 16–17, 97
!=
(not equal) operator, 97–98, 100–102
create strings with double-quotes vs., 29
escaping inside strings, 34–36
indicating strings, 57
'''
(triple-single-quotes), 36
errors when putting spaces between, 33
escaping inside strings, 34, 36
/
(slash) character, 16–17, 257
(backslash) character, 33–34, 257
\
(double backlash) character, 36
_
(underscore) character, 20–21, 62, 189
function of, 21
practicing Boolean logic, 100–102
in truth tables, 98
as truth term, 97
=
(single-equal) operator, 21
#
(pound or octothorpe) character, 12, 14–15, 17
%
(percent) operator, 16, 17–18
[]
left and right brackets, lists
, 112–114
^
(caret) character, view output, 11
{}
characters, embedded variables in strings, 24–25
<>
, !=
(not equal) vs., 102
>
(greater than) operator, 16–17, 91
activate
script, Powershell, 195
Addresses, web, 225
altered()
function, inheritance, 180–183
and
app.py
write automated tests for forms, 231–232
apropos
command, 252
Arguments, creating functions, 62, 66
argv
as argument variable, 42
prompting and passing using, 46–47
reading and writing files, 54
using input()
vs., 44
Arrays, lists vs., 114
ASCII (
American Standard Code for Information Interchange), 80–81
assert_equal()
function, automated testing, 201–203
assert_raises()
function, writing test expected to fail, 215
Atom
text editor
macOS setup, 2
working with first program, 9
for forms, 232
improving, 242
refactoring gothonweb
game using, 238–239
Backslash () character, 33–34, 257
Bash references, 283
Big5 encoding, 85
bin
directory, skeleton project directory, 198
Boolean logic
memorizing vs. learning, 98
rules for if-statement
s, 126
Bottom up processes, vs. top down, 169
Branches and functions, 122–124
Browser
create engine to run game in, 234–241
getting input from. See Input, getting from browser
how it accesses information, 225–226
Bytes
breaking files, 85
conventions for encoding, 80–81
defined, 78
dissecting output, 82
C3 algorithm, super()
function, 183
Cardinal numbers, lists, 120–121, 137
caret (^
) character, view output, 11
cat
command, print whole file, 57, 252, 278–279
cd
command, change directory
macOS/Linux, 251
Windows, 252
cd~
command, 255
Characters
encoding. See Strings, bytes, and character encodings
importance of learning names of, 76
Checklist, creating function, 62
Child classes. See Inheritance vs. composition
Classes
adds consistency to program, 146
as blueprints for new mini-modules, 149
design hierarchy in OOP, 166–167
inheritance vs. composition. See Inheritance vs. composition
object-oriented phrase drill, 152–153
object-oriented reading test, 154–155
object-oriented word drill, 152
researching Python, 137
similarity to modules, 147–148
styling, 189
as templates minting new objects, 186
CLI (command line interface), using on GUI, 261
close
command, close file, 52–53
Code
avoid hard coding filenames, 48
create one line of, 57
finding errors in, 132
inheritance vs. composition for reusable, 185
OOP analysis and design, 170–176
practicing English to, 155
reading, 132
reading backward. See Reading code backward
reading phrases, 156
refactoring for gothonweb
game, 234–239
researching piece of, 78
styling, 190
testing other programmer’s, 94
typing into Terminal/PowerShell, 50
Colon (:
), creating functions, 61–62
Colors, in text editors, 12
change directory (cd
), 258–261
exit your terminal (exit
), 282
introduction, 248
make directory (mkdir
), 255–257
make empty files (touch
/New-Item
), 271–272
memorizing things, 249
move around (pushd
, popd
), 268–271
paths, folders, directories (pwd
), 253–255
PowerShell references, 283
remove directory (rmdir
), 265–268
Unix Bash references, 283
view file (less
/more
), 277–278
Command line interface (CLI), using on GUI, 261
Commands
converting arguments to strings, 44
as functions and methods, 50
learning, 44
Comments
adding when reading code, 132
creating functions with, 65–66
designing/debugging with, 127
functions/files with, 69
getting help with documentation, 92
is-a/has-a relationships using, 159–160
reading/writing files using, 53
variable names, 21
writing good, 190
writing when you do not understand code, 29, 124
Composition
defined, 152
when to use inheritance or, 185
Conventions, for encoding text, 80–81
Copying files, writing script for, 56–58
cp
, copy file or directory
macOS/Linux, 251
Windows, 252
curl
command, generate request types, 232
Data structures
Data types, list of, 129
DBES (Decode Bytes, Encode Strings), dissecting code, 83–84
Debugging
fixing errors in first website, 219
refactored code, 241
dedent()
function, """
-style strings, 170–175
branches and functions, 122–124
defined, 152
files working with functions, 68–70
functions can return something, 72–74
functions working with variables, 90–93
is-a/has-a relationships, 159–160
del
keyword, delete from dictionary, 141
Designing and debugging, 126–127
dict
how forms work, 227
understanding dictionaries, 140–144
Dictionaries
store scenes by name in, 175
die
function, if-statement
rules, 126
dir -r
, find files in Windows, 253
causes of ImportErrors
, 209
“Hello World” web application, 217
Linux/macOS command-line for, 251
skeleton project. See Skeleton project directory
Windows command-line for, 252
Django Tutorial, 244
Documentation
check out projects/build something using, 244
getting help with comments, 92
writing good comments, 190
Dot (.
) operator, 146–148, 193
Double backlash (\
), 36
Double-quotes. See "
(double-quotes)
echo
, print some arguments, 252, 253
Elements, accessing list, 120–121
elif
branches and functions, 122–124
and else
, 107
else
branches and functions, 122–124
rules for if-statement
s, 126
Encodings, bytes/character, 80–85
env
command, look at your environment, 252
Equal operator. See ==
(equal) operator
Error messages
building first website, 218–219
EOFError
, 155
ImportError
. See ImportError
s
NameError
, 47
printing, 29
for spaces between triple-quotes, 33
for spelling mistakes, 33
ValueError
. See ValueError
s
variable names, 21
viewing output in first program, 11
when making script shorter, 58
Escape sequences
for different characters in strings, 34–35
practicing, 87
reading and writing files, 54
reviewing, 130
supported by Python, 35
except
keyword, exceptions, 206
Exceptions
and numbers, 206
exists
command, copying files, 56–58
exit
command, exit shell, 124, 252, 282
export
command, export new environment variable, 252
f
character
embedding variables inside strings, 24–25
in readline()
, 70
using with functions, 69
False
keyword
avoid quotes around, 31
object-oriented reading test, 154–155
Features
adding to script, 42
File Transfer Protocol (FTP), and URLs, 225
Files
creating, 50
Linux/macOS command-line for, 251–252
Windows command-line for, 252–253
find
command, files, 252
flask
framework
create basic templates for website, 219–221
ImportError
after installing, 222
installing for first website, 216
make “Hello World” web application, 216–217
testing tricks for creating fake sessions, 242
web.py
vs., 221
what is going on, 218
FLASK_DEBUG
, not safe to activate on Internet, 219
Flow charts, 132
Folders. See Directories
foo
, OOP, 152
rules for, 126
when to use lists, 137
while-loops
vs., 118
forfiles
, 253
Format strings
formatter.format()
, 30
reading and writing files, 54
.format()
syntax, formatting strings, 26–27, 30
Forms
automated tests for, 232
FTP (File Transfer Protocol), and URLs, 225
Functions
accessing in module with .
(dot) operator, 146–147
also called methods/commands, 50
create checklist for, 62
reading code, 132
replicating implicit inheritance, 184–185
styling, 189
using print
vs. return
in, 93
viewing calls, 137
overview of, 234
Games
analysis and design. See Object-oriented analysis and design
gothonweb
project
analysis of simple game engine, 165–169
creating layout template, 234–239
making into first web application, 217–221
refactoring code/creating web engine to run, 234–241
Grammar, making sentences, 211, 215
Greater-than-equal (>=
) operator, 16–17, 97
Greater than (>
) operator, 16–17, 91
grep
command, find things inside files, 252
GUI (graphical user interface), using CLI on, 261
Hard coded filenames, avoid, 48
has-a relationships, 152, 158–162
“Hello World” web application
create basic templates, 219–221
Help
create system for, 242
getting module, 92
help
command, Windows, 253
helpctr
command, Windows, 253
hostname
my computer’s network name, 251, 252
understand URLs, 225
HTML
create basic templates for website, 219–221
improve appearance of, 242
research, 232
understand response, 226
HTTP
research HTTP REC, 232
understand URLs, 225
if-else
, try-except
vs., 209
if-statements
branches and functions, 122–124
make decisions, 83–84, 108–110
read code, 132
rules for, 126
Implicit inheritance
combine with other types of inheritance, 182
import
add features to script, 42
file with modules, 146
make a game yourself, 188
objects as similar to, 148–149
after installing flask
, 222
create skeleton project directory, 199
Increment by ( +=
) operator, 69–70, 105
index()
create HTML forms, 229
how forms work, 227
index.GET
handler, 224
Inheritance
object-oriented phrase drill, 152
object-oriented reading test, 154–155
object-oriented word drill, 152
alter behavior before or after, 180–181
implicit inheritance, 179
override explicitly, 180
overview of, 178
reason for super()
, 183
three kinds of inheritance combined, 182–183
understand composition, 184–185
understand inheritance, 178–179
using inheritance vs. composition, 185
using super()
with __init__()
, 183
initializing newly created empty object, 149
in is-a/has-a relationships, 159–162
running reliably for parent class, 162
trying not to do too much in, 189
using self
when making functions for classes, 151
using super()
in, 183
input()
entering own values, 74
parameter to ('>'
), 124
parameters, unpacking, variables, 42–44
overview of, 204
breaking it, 232
creating layout template, 229–230
writing automated tests for forms, 232
Internet, flask
debugger mode not safe on, 219
Internet research
check out projects/try to build something, 244
functions and files, 69
import
statement, 57
object-oriented programming, 137, 151
reading files, 49
int()
function, converting command line argument strings, 44
IP addresses, and URLs, 225
is-a relationships, 152, 158–162
Jinja2 Documentation, template language, 221
Kivy, 244
Layout template, create, 232
Learn C The Hard Way, 244
Learn Ruby The Hard Way, 244
less
command, view file in macOS/Linux, 252, 277–278
Less-than-equal (<=
) operator, 16–17, 97
Lexicon, creating game
make sentences. See Sentences, making
Libraries, defined, 43
alternative text editors for, 7
get terminal open and working, 250–251
project skeleton setup, 192–194
Linux/macOS command-line
cd
, change directory, 258–259, 261
cp
, copy file or directory, 272, 274–275
exit
, exit shell, 282
mkdir
, make directory, 256–257
mv
, move file or directory, 275, 277
pushd
, popd
(move directory)
, 268–271
pwd
, print working directory, 253–255
rmdir
, remove directory, 266, 268
Lists
build using for-loops
, 112–114
making 2-D, 114
processing lists of things, 78
when to use, 137
localhost
web connection, 225
Logic
Login, researching web application, 242
Lookup tables, dictionaries as, 144
Loops
for-loops
. See for-loops
making infinite, 124
while-loops
. See while-loops
lpthw
virtual environment, skeleton project, 193, 195
ls
, list directory
macOS/Linux, 251
Windows, 252
macOS. See Linux/macOS
main
function, dissecting code, 83
man
, read manual page in macOS/Linux, 252
Map class
gothonweb
project code, 171
storing scenes by name in dictionary, 175
Maps
analysis of simple game engine, 165
completing game, 242
match
function, parser code, 212
Memorization
of commands using index cards, 251–253
learning command line, 249
tips for, 96
Method resolution order (MRO), super()
, 183
Methods
also called functions and commands, 50
functions vs., 189
mkdir
, make directory
macOS/Linux, 251
Windows, 252
Modifiers, reading and writing files, 54
Modules
causes of ImportError
s, 209
getting help for, 92
replicating implicit inheritance in, 184–185
more
command, view file in Windows, 252, 278
MRO (method resolution order), super()
, 183
Multiple inheritance, avoid, 178, 183, 185
mv
command, move file or directory
macOS/Linux, 251
Windows, 252
NameError
message, 47
Names
importance of learning symbol, 76
Natural Language Tool Kit, 244
Nested structures
lists as, 112
rules for if-statement
s, 126
new-item
command, create empty files in Windows, 271–272
None
, for some functions, 93
nosetests
command
automated tests for forms, 231
create skeleton project directory, 197–199
syntax error, 203
not
as truth term, 97
Not equal (!=
) operator, 97–98, 100–102
Nouns, object-oriented programming, 164–167
Numbers
access elements of lists, 120–121
exceptions and, 206
input to do math, 39
between range of numbers, 110
rounding floating point, 25
Object-oriented analysis and design. See also Game, start of your web
analysis of simple game engine, 165
code classes and test to run them, 167–169
code for “Gothons from Planet Percal #25,” 170–176
create class hierarchy/object map for concepts, 166–167
extract/research key concepts, 166
repeat and refine, 169
top down vs. bottom up, 169
what you should see, 176
write or draw about problem, 165
Object-oriented programming (OOP)
inheritance vs. composition. See Inheritance vs. composition
Python as, 146
Objects
classes as templates that mint new, 186
object-oriented phrase drill, 152–153
object-oriented word drill, 152
Octothorpe (#
) character, 12, 14–15, 17
open
command, reading and writing files, 52–54
Operators
finding more Python equality, 102
or
as truth term, 96
Order, maintain with lists, 137
Ordinal numbers, lists, 120–121
Output
“Hello World” web application, 217
override()
function, inheritance, 189
Pandas, 244
Paragraphs, if-statement
rules, 126
Parameters, reading and writing files, 54
Parent classes. See Inheritance vs. composition
Parser
ParserError
exception, 211–214
PEMDAS acronym, order of math operations, 18
Percent (%
) operator, 16, 17–18
Phrase drills, object-oriented, 152–156
pip3.6
(or just pip
)
create skeleton project directory, 192–195, 198–199
install flask
to build first website, 216
planisphere_tests.py
file, 238–239
popd
command, pop directory
macOS/Linux, 251
Windows, 252
Ports, web connections, 225
POST
automated tests for forms, 231
Pound (#
) character, 12, 14–15, 17
PowerShell
create game engine, 240
references, 283
typing code into, 50
Windows 10 setup for, 3–4, 195, 250–251
print
debug with, 127
read code using, 132
when functions use return
vs., 93
Print strings
with more complicated formatting, 30–31
more exercises in, 28–29, 32–33
print_a_line
, pass in current line number, 68–69
print_line
function, dissecting code, 83–84
print_two
function, create functions, 60–61
Programming languages
advice from old programmer, 246–247
check out projects/try to build something, 244
how to learn new, 245
learning command line. See Command-line crash course
Prompts
identify in appendix exercises, 254
Prototype languages, 186
Pseudo code, test first using, 207
pushd
command, push directory
macOS/Linux, 251
Windows, 252
pwd
command, print working directory
macOS/Linux, 251
Windows, 252
.py
files, passing variables to script, 42–44
pydoc
command, prompt people, 40–41
PyGame, 244
PYTHONPATH
environment variable, 240
quit()
function, reload Python after, 92
raise
keyword, exceptions, 211, 213–214
range()
function, loops, 114
read
command, read contents of file, 52–54
Reading
code, 132
code out loud, 190
comments and pound characters, 14
defined, 88
printing, 29
reasons for, 15
understanding how to, 22
readline()
function, 52–53, 68, 70, 83
render_template()
function, 220–221
request.args
, forms, 227
Requests, web
generating types of with curl
, 232
learn client side of HTTP, 244
understand, 225
Responses, web, 226
object-oriented reading test, 155
when functions use print
vs., 93
rmdir
command, remove directory
macOS/Linux, 251
Windows, 252
Room
class
refactor code for gothonweb
game, 234–239
round()
function, floating point numbers, 25
Rules
for if-statement
s, 126
when to use inheritance or composition, 185
runas
command, danger in windows, 252
Scanning input, lexicon tuples, 205, 209
Scenes (rooms)
analysis of simple game engine, 165–167
code classes for simple game, 167–169
gothonweb
project code, 170–176
what you should see, 176
SciPy, 244
ScraPy, 244
Scripts
linking functions to, 61
making decisions, 107
Search engines
finding things on Internet, 5–6
how to type #
(octothorp) character, 15
seek()
function
does not set current line to 0, 70
research for file
, 69
select-string
command, find things inside Windows files, 253
self
is-a/has-a relationships and, 159–160
object-oriented language, 152–155
breaking up, 205
exceptions, 211
grammar, 211
overview of, 210
what you should test, 215
Servers, how browsers access information on, 226
set
command, export/set new environment variable in Windows, 253
Setup exercise
finding things on Internet, 5–6
overview of, 2
warnings for beginners, 6
setup.py
file, skeleton project directory, 196, 198–199
Single-equal (=
) operator, 21
Single-quotes. See '
(single-quotes)
creating directory structure, 195–197
overview of, 192
required quiz, 198
using, 198
skip
keyword, parser code, 213
Slash (/
) character, 16–17, 257
Space
adding around operators for easier reading, 22
make code readable with vertical, 190
Spelling mistakes, error messages for, 33
Stop words, parser code, 213
Strings
complicated formatting of, 30–31
convert command line arguments to, 44
decode bytes and encode, 83–84
list of escape sequences for, 130
list of old style formats for, 130–131
pound characters in, 15
read/write files in, 54
start new line in, 33
understanding, 26
as UTF-8 encoded sequence of characters, 82
Strings, bytes, and character encodings
breaking it, 85
dissect output, 82
overview of, 78
switches and conventions, 80–81
Styling
code, 190
functions and classes, 189
Subject
sudo
command, 252
super()
function, inheritance, 180–183
Symbols
data types, 129
escape sequences for strings, 130
learning names of, 76
old style string formats, 130–131
reading code, 132
SyntaxError
message
EOL
, 58
prompting and passing, 47
pydoc
, 41
viewing output in first program, 11
System site packages, setup for skeleton project, 193
Tables
dictionaries as lookup, 144
Templates
create HTML forms, 229
templates/index.html
file, 219–221, 229–230
templates/layout.html
file, 230
TensorFlow, 244
Terminal
getting open and working, 250–251
Linux setup, 5
typing code into, 50
what you should see in first program, 9–11
Terminology
Test first programming tactic, 206–207
Test_directions
test case, 207–209
Tests. See also Automated tests
code for classes in OOP, 168–169
object-oriented reading, 153–155
other programmer’s code, 94
session-based game engine, 241
skeleton project directory setup, 197–198
tricks for creating fake sessions inside, 242
tests/app_tests.py
, 231
Test.txt
file, copying files, 56–58
Text
Text editors
getting colors in, 12
macOS setup, 2
Things, getting things from, 149–150
Top down process
OOP design, 164
vs. bottom up, 169
touch
command, make empty files in macOS/Linux, 271–272
Tracing variables, reading code, 132
Triple-quotes ("""
). See """
(triple-quotes)
Triple-single-quotes ('''
), 36
True
keyword
avoid putting quotes around, 31
object-oriented reading test, 154–155
as truth term, 97
Truth
try-except
, if-else
vs., 209
try
keyword, exceptions, 206
Tuples, lexicon, 205
type
command, print whole file in Windows, 252
Underscore (_
) character, 20–21, 62, 189
Unicode, 81
URLs (Uniform Resource Locators)
build first website, 218
create HTML forms, 228
how forms work, 227
overview of, 225
User input. See Input, advanced user
UserWarning
, when running nosetests
, 203
UTF-8
standard
comparing UTF-16
/UTF-32
to, 84–85
dissecting output, 82
encoding text in Python, 81
fixing terminal unable to display, 79
and numbers, 206
parameters/unpacking/variables, 44
prompting/passing, 47
Variables
avoid module or global, 189
for-loop
using undefined, 114
and names/code/functions, 60–62
reading code, 132
temporarily inside functions, 87–88
writing strings with text, 26–27
.venvs
directory, skeleton project setup, 193–195
Verbs
analyze class hierarchy in OOP, 165
extract key concepts in OOP, 164
Warnings
setup, 2
Web
breaking applications, 232
learn client side of, 244
start of your game. See Game, start of your web
Website, your first
create basic templates, 219–221
install flask
framework, 216
make “Hello World” web application, 216–217
what is going on, 218
reading code, 132
rules, 126
when to break rule about not using, 138
while True
, make infinite loop, 124
Windows
alternative text editors for, 7
skeleton project directory setup, 194–195
Windows command-line
cat
, stream file, 259–261, 278–279
cp
, copy file or directory, 272–275
exit
, exit shell, 282
getting PowerShell open and working for, 250–251
macOS setup, 2
more
, view file, 278
mv
, move file or directory, 275–277
pushd
, popd
(move directory), 269–271
pwd
, print working directory, 254–255
rmdir
, remove directory, 266–268
Word drills, object-oriented, 152–155
words.pop
function, 93
Write
formulas using functions, 74
xargs
command, execute arguments, 252
18.234.139.149