131
Symbols
=
(assignment) operator, 18, 34
\
(backslash), 124, 151, 162, 174–175
line continuation character, 93
^
(caret symbol), 162
matching beginning of string,
159–160
negative character classes, 159
:
(colon), 38, 45, 54, 82, 127
{}
(curly brackets), 105, 162
greedy vs. nongreedy matching,
156–157
matching specific repetitions
with, 156
$
(dollar sign), 159–160, 162
.
(dot character), 160–162
using in paths, 175–176
wildcard matches, 160–162
"
(double quotes), 124
**
(exponent) operator, 15
==
(equal to) operator, 33, 34
/
(forward slash), 174–175
division operator, 15, 88
>
(greater than) operator, 33
>=
(greater than or equal to)
operator, 33
#
(hash character), 126
//
(integer division/floored quotient)
operator, 15
<
(less than) operator, 33
<=
(less than or equal to) operator, 33
%
(modulus/remainder) operator,
15, 88
*
(multiplication) operator, 15, 83, 88
!=
(not equal to) operator, 33
()
(parentheses), 96–97, 152–153
|
(pipe character), 153–154, 164–165
+
(plus sign), 155–156, 162
addition operator, 15, 17, 83, 88
?
(question mark), 154–155, 162
'
(single quote), 124
[]
(square brackets), 80, 162
*
(star), 162
using with wildcard character, 161
zero or more matches with, 155
-
(subtraction) operator, 15, 88
'''
(triple quotes), 125, 164
_
(underscore), 20
A
%A
directive, 344
%a
directive, 344
absolute paths, 175–179
abspath()
function, 177
addition (
+
) operator, 15, 17, 83, 88
additive color model, 389
add_heading()
method, 314
addPage()
method, 299
add_paragraph()
method, 313–314
add_picture()
method, 315
add_run()
method, 313–314
algebraic chess notation, 112–113
all_caps
attribute, 311
ALL
search key, 369
alpha, defined, 388
and
operator, 35
ANSWERED
search key, 370
API (application programming
interface), 327–328
append()
method, 89–90
application-specific passwords, 365
args
keyword, 349
arguments, function, 23, 63
keyword arguments, 65–66
passing to processes, 354
passing to threads, 348–349
assertions, 219–221
disabling, 445
assignment (
=
) operator, 18, 34
AT&T mail, 363, 367
attributes, HTML, 241, 248
augmented assignment operators,
88–89
In d e x
142
462
Index
B
\b
backspace escape character, 419
%B
directive, 344
%b
directive, 344
back()
method, 261
backslash (
\
), 124, 151, 162, 174–175
BarChart()
function, 290
basename()
function, 178
BCC
search key, 370
Beautiful Soup, 245. See also
bs4
module
BeautifulSoup
objects, 245–246
BEFORE
search key, 369
binary files, 180–181, 184–185
binary operators, 35–37
bitwise or operator, 164–165
blank strings, 17
blocking execution, 337
blocks of code, 37–38
BODY
search key, 369
bold
attribute, 311
Boolean data type
binary operators, 35–36
flow control and, 32–33
in
operator, 87
not in
operator, 87
“truthy” and “falsey” values, 53
using binary and comparison
operators together, 36–37
box tuples, 390
breakpoints, debugging using, 229–231
break
statements
overview, 49–50
using in for loop, 55
browser, opening using
webbrowser
module, 234–236
bs4
module
creating object from HTML,
245–246
finding element with
select()
method, 246–247
getting attribute, 248
overview, 245
built-in functions, 57
bulleted list, creating in Wiki markup,
139–141
copying and pasting clipboard,
139–140
joining modified lines, 141
overview, 139
separating lines of text, 140
C
calling functions, 23
call stack, defined, 217
camelcase, 21
caret symbol (
^
), 162
matching beginning of string,
159–160
negative character classes, 159
Cascading Style Sheets (CSS)
matching with
selenium
module, 258
selectors, 246–247
case sensitivity, 21, 163
CC
search key, 370
Cell
objects, 268–269
cells, in Excel spreadsheets, 266
accessing
Cell
object by its name,
268–269
merging and unmerging, 286–287
writing values to, 278–279
center()
method, 133–134, 426
chaining method calls, 398
character classes, 158–159, 162
character styles, 310
charts, Excel, 288–290
chdir()
function, 175
Chrome, developer tools in, 242–243
clear()
method, 258
click()
function, 420, 430, 431
clicking mouse, 420
click()
method, 259
clipboard, using string from, 236
CMYK color model, 389
colon (
:
), 38, 45, 54, 82, 127
color values
CMYK vs. RGB color models, 389
RGBA values, 388–389
column_index_from_string()
function, 270
columns, in Excel spreadsheets
setting height and width of,
285–286
slicing
Worksheet
objects to get
Cell
objects in, 270–272
Comcast mail, 363, 367
comma-delimited items, 80
command line arguments, 235
commentAfterDelay()
function, 429
comments
multiline, 126
overview, 23
133
Index
463
comparison operators
overview, 33–35
using binary operators with, 36–37
compile()
function, 151, 152, 164–165
compressed files
backing up folder into, 209–212
creating ZIP files, 205–206
extracting ZIP files, 205
overview, 203–204
reading ZIP files, 204
computer screen
coordinates of, 415
resolution of, 416
concatenation
of lists, 83
string, 17–18
concurrency issues, 349
conditions, defined, 37
continue
statements
overview, 50–53
using in
for
loop, 55
Coordinated Universal Time (UTC), 336
coordinates
of computer screen, 415
of an image, 389–390
copy()
function, 100–101, 135, 198, 394
copytree()
function, 198–199
countdown project, 357–358
counting down, 357
overview, 357
playing sound file, 357–358
cProfile.run()
function, 337
crashes, program, 14
create_sheet()
method, 278
CRITICAL
level, 224
cron, 354
cropping images, 393–394
CSS (Cascading Style Sheets)
matching with
selenium
module, 258
selectors, 246–247
CSV files
defined, 319
delimeter for, 324
format overview, 320
line terminator for, 324
Reader
objects, 321
reading data in loop, 322
removing header from, 324–327
looping through CSV files, 325
overview, 324–325
reading in CSV file, 325–326
writing out CSV file, 326–327
Writer
objects, 322–323
curly brackets (
{}
), 105, 162
greedy vs. nongreedy matching,
156–157
matching specific repetitions
with, 156
current working directory, 175
D
\D
character class, 158
\d
character class, 158
%d
directive, 344
data structures
algebraic chess notation, 112–113
tic-tac-toe board, 113–117
data types
Booleans, 32
defined, 16
dictionaries, 105–106
floating-point numbers, 17
integers, 17
list()
function, 97
lists, 80
mutable vs. immutable, 94–96
None
value, 65
strings, 17
tuple()
function, 97
tuples, 96–97
datetime
module
arithmetic using, 343
converting objects to strings,
344–345
converting strings to objects, 345
fromtimestamp()
function, 341
now()
function, 341
overview, 341–342, 346
pausing program until time, 344
timedelta
data type, 342–343
total_seconds()
method, 342
datetime
objects, 341–342
converting to strings, 344–345
converting from strings to, 345
debug()
function, 222
debugging
assertions, 219–221
defined, 4
getting traceback as string, 217–218
in IDLE
overview, 225–227
stepping through program,
227–229
using breakpoints, 229–231
153
464
Index
debugging (continued)
logging
disabling, 224–225
to file, 225
levels of, 223–224
logging
module, 221–223
print()
function and, 223
raising exceptions, 216–217
DEBUG
level, 223
decimal numbers. See floating-point
numbers
decode()
method, 374–375
decryption, of PDF files, 297–298
deduplicating code, 62
deepcopy()
function, 100–101
def
statements, 62
with parameters, 63
DELETED
search key, 370
delete_messages()
method, 375
deleting files/folders
permanently, 200–201
using
send2trash
module, 201–202
del
statements, 84
dictionaries
copy()
function, 100–101
deepcopy()
function, 100–101
get()
method, 109
in
operator, 109
items()
method, 107–108
keys()
method, 107–108
lists vs., 106–107
nesting, 117–119
not in
operator, 109
overview, 105–106
setdefault()
method, 110–111
values()
method, 107–108
directories
absolute vs. relative paths, 175–176
backslash vs. forward slash, 174–175
copying, 198–199
creating, 176
current working directory, 175
defined, 173–174
deleting permanently, 200–201
deleting using
send2trash
module,
201–202
moving, 199–200
os.path
module
absolute paths in, 177–179
file sizes, 179–180
folder contents, 179–180
overview, 177
path validity, 180
relative paths in, 177–179
renaming, 199–200
walking, 202–203
dirname()
function, 178
disable()
function, 224
division (
/
) operator, 15, 88
Document
objects, 307–308
dollar sign (
$
), 159–160, 162
dot character (
.
), 160–162
using in paths, 175–176
wildcard matches, 160–162
dot-star character (
.*
), 161
doubleClick()
function, 420, 430
double quotes (
"
), 124
double_strike
attribute, 311
downloading
files from web, 239–240
web pages, 237–238
XKCD comics, 251–256, 350–352
DRAFT
search key, 370
dragging mouse, 420–422
dragRel()
function, 420, 422, 430
dragTo()
function, 420, 430
drawing on images
ellipses, 407
example program, 407–408
ImageDraw
module, 406
lines, 406–407
points, 406
polygons, 407
rectangles, 407
text, 408–410
dumps()
function, 329
duration
keyword arguments, 416
E
ehlo()
method, 364, 379
elements, HTML, 240
elif
statements, 40–45
ellipse()
method, 407
else
statements, 39–40
email addresses, extracting, 165–169
creating regex, 166–167
finding matches on clipboard,
167–168
joining matches into a string, 168
overview, 165–166
emails
deleting, 375
disconnecting from server, 375–376
fetching
122
Index
465
folders, 368–369
getting message content,
372–373
logging into server, 368
overview, 366–367
raw messages, 373–375
gmail_search()
method, 372
IMAP, 366
marking message as read, 372–373
searching, 368–371
sending
connecting to SMTP server,
363–364
disconnecting from server, 366
logging into server, 364–365
overview, 362
reminder, 376–380
sending “hello” message, 364
sending message, 365
TLS encryption, 364
SMTP, 362
emboss
attribute, 311
encryption, of PDF files, 302–303
endswith()
method, 131
epoch timestamps, 336, 341, 346
equal to (
==
) operator, 33, 34
ERROR
level, 224
errors
crashes and, 14
help for, 8–9
escape characters, 124–125
evaluation, defined, 14
Excel spreadsheets
application support, 265–266
charts in, 288–290
column width, 285–286
converting between column letters
and numbers, 270
creating documents, 277
creating worksheets, 278
deleting worksheets, 278
font styles, 282–284
formulas in, 284–285
freezing panes, 287–288
getting cell values, 268–269
getting rows and columns, 270–272
getting worksheet names, 268
merging and unmerging cells,
286–287
opening documents, 267
openpyxl
module, 266
overview, 266–267
reading files
overview, 272–273
populating data structure,
274–275
reading data, 273–274
writing results to file, 275–276
and reminder emails project,
376–380
row height, 285–286
saving workbooks, 277
updating, 279–281
overview, 279–280
setup, 280
workbooks vs., 266
writing values to cells, 278–279
Exception
objects, 217
exceptions
assertions and, 219–221
getting traceback as string, 217–218
handling, 72–74
raising, 216–217
execution, program
defined, 31
overview, 38
pausing until specific time, 344
terminating program with
sys.exit()
, 58
exists()
function, 180
exit codes, 353–354
expand
keyword, 398
exponent (
**
) operator, 15
expressions
conditions and, 37
in interactive shell, 14–16
expunge()
method, 375
extensions, file, 173
extractall()
method, 205
extracting ZIP files, 205
extract()
method, 205
F
FailSafeException
exception, 434
“falsey” values, 53
fetch()
method, 371, 372–373
file editor, 21
file management
absolute vs. relative paths, 175–176
backslash vs. forward slash, 174–175
compressed files
backing up to, 209–212
creating ZIP files, 205–206
129
466
Index
file management (continued)
compressed files (continued)
extracting ZIP files, 205
overview, 203–204
reading ZIP files, 204
creating directories, 176
current working directory, 175
multiclipboard project, 191–193
opening files, 181–182
os.path
module
absolute paths in, 177–179
file sizes, 179–180
folder contents, 179–180
overview, 177
path validity, 180
relative paths in, 177–179
overview, 173–174
paths, 173–174
plaintext vs. binary files, 180–181
reading files, 182–183
renaming files, date styles, 206–209
saving variables with
pformat()
function, 185–186
send2trash
module, 201–202
shelve module, 184–185
shutil
module
copying files/folders, 198–199
deleting files/folders, 200–201
moving files/folders, 199–200
renaming files/folders, 199–200
walking directory trees, 202–203
writing files, 183–184
filenames, defined, 173
File
objects, 182
findall()
method, 157–158
find_element_by_*
methods, 257–258
find_elements_by_*
methods, 257–258
Firefox, developer tools in, 243
FLAGGED
search key, 370
flipping images, 398–399
float()
function, 25–28
floating-point numbers
integer equivalence, 27
overview, 17
rounding, 338
flow control
binary operators, 35–36
blocks of code, 37–38
Boolean values and, 32–33
break
statements, 49–50
comparison operators, 33–35
conditions, 37
continue
statements, 50–53
elif
statements, 40–45
else
statements, 39–40
if
statements, 38–39
overview, 31–32
using binary and comparison
operators together, 36–37
while
loops, 45–49
folders
absolute vs. relative paths, 175–176
backing up to ZIP file, 209–212
creating new ZIP file, 211
figuring out ZIP filename,
210–211
walking directory tree, 211–212
backslash vs. forward slash, 174–175
copying, 198–199
creating, 176
current working directory, 175
defined, 173–174
deleting permanently, 200–201
deleting using
send2trash
module,
201–202
moving, 199–200
os.path
module
absolute paths in, 177–179
file sizes, 179–180
folder contents, 179–180
overview, 177
path validity, 180
relative paths in, 177–179
renaming, 199–200
walking directory trees, 202–203
Font
objects, 282–283
font styles, in Excel spreadsheets,
282–284
for
loops
overview, 53–56
using dictionary items in, 108
using lists with, 86
format
attribute, 392
format_description
attribute, 392
formData
list, 434
form filler project, 430–437
overview, 430–431
radio buttons, 435–436
select lists, 435–436
setting up coordinates, 432–434
steps in process, 431
submitting form, 436–437
typing data, 434–435
Documents you may be interested
Documents you may be interested