Introduction to Python Slide Index

Symbols and Numbers

!= operator, 1-40
#, program comment, 1-32
%, floating point modulo operator, 1-54
%, integer modulo operator, 1-50
%, string formatting operator, 2-25
&, bit-wise and operator, 1-50
&, set intersection operator, 2-22
() operator, 5-29
(), tuple, 2-6
**, power operator, 1-54
*, list replication, 1-69
*, multiply operator, 1-50, 1-54
*, sequence replication operator, 2-30
*, string replication operator, 1-60
+, add operator, 1-50, 1-54
+, list concatenation, 1-67
+, String concatenation, 1-59, 9-24
-, set difference operator, 2-22
-, subtract operator, 1-50, 1-54
-i option, Python interpreter, 7-26
-O option, Python interpreter, 7-22, 7-23
. operator, 5-29
... interpreter prompt, 1-15
.NET framework, and IronPython, 12-45
.pyc files, 4-11
.pyo files, 4-11
/ division operator, 1-54
/, division operator, 1-50
//, floor division operator, 1-50, 1-51
< operator, 1-40
<<, left shift operator, 1-50
<= operator, 1-40
== operator, 1-40
> operator, 1-40
>= operator, 1-40
>>, right shift operator, 1-50
>>> interpreter prompt, 1-15
[:] string slicing,, 1-59
[:], slicing operator, 2-31
[], sequence indexing, 2-29
[], string indexing, 1-59
\ Line continuation character, 1-43
^, bit-wise xor operator, 1-50
{}, dictionary, 2-13
|, bit-wise or operator, 1-50
|, set union operator, 2-22
~, bit-wise negation operator, 1-50

A

ABC language, 1-5
abs() function, 1-50, 1-54, 4-24
Absolute value function, 1-50, 1-54
__abs__() method, 5-26
Accessor methods, 6-30
Adding items to dictionary, 2-14
__add__() method, 5-26
Advanced String Formatting, 9-31
and operator, 1-40
__and__() method, 5-26
Anonymous functions, 3-45
append() method, of lists, 1-67
Argument naming style, 3-20
Arguments, passing mutable objects, 3-25
Arguments, transforming in function, 3-22
argv variable, sys module, 4-28
array module, 10-24
array module typecodes, 10-25
array object I/O functions, 10-27
array object operations, 10-26
arrays vs. lists, 10-28
arrays, creating with ctypes, 10-20
assert statement, 7-20
assert statement, stripping in -O mode, 7-22
assertEqual() method, unittest module, 7-15
AssertionError exception, 7-20
Assertions, and unit testing, 7-15
assertNotEqual() method, unittest module, 7-15
assertRaises() method, unittest module, 7-15
assert_() method, unittest module, 7-15
Assignment, copying, 2-65
Assignment, reference counting, 2-62, 2-64, 2-65
Associative array, 2-13
Attribute access functions, 5-31
Attribute binding, 6-12
Attribute lookup, 6-17, 6-20
Attribute, definition of, 5-3
Attributes, computed using properties, 6-33, 6-36, 6-37
Attributes, modifying values, 6-13
Attributes, private, 6-27
Awk, and list compreheneions, 2-57

B

Base class, 5-11
base-10 decimals, 4-58
__bases__ attribute of classes, 6-19
binary arrays, 10-24
binary data, 10-4
binary data representation, 10-6
Binary files, 10-9
binary type objects, 10-16
Binding of attributes in objects, 6-12
Block comments, 1-32
Boolean type, 1-46, 1-47
Booleans, and integers, 1-47
Boost Python, 12-31
Bottom up programming style, 3-11
break statement, 2-36
Breakpoint, debugger, 7-29
Breakpoint, setting in debugger, 7-31
Built-in exceptions, 3-52
__builtins__ module, 4-23
bytearray type, 10-8
bytes literals, 10-7

C

C extension, example with ctypes, 12-25
C extensions, accessing with ctypes module, 12-23
C Extensions, other tools, 12-31
C3 Linearization Algorithm, 6-23
Callback functions, 3-44
Calling a function, 1-76
Calling other methods in the same class, 5-9
Capturing output of a subprocess, 11-17
Case conversion, 1-61
Catching exceptions, 1-79
Catching multiple exceptions, 3-54
chr() function, 4-25
Class implementation chart, 6-11
class statement, 5-4
class statement, defining methods, 5-8
Class,, 6-9
Class, representation of, 6-9
Class, __slots__ attribute of, 6-38
__class__ attribute of instances, 6-10
close() function, shelve module, 4-46
Code blocks and indentation, 1-37
Code formatting, 1-43
Code reuse, and generators, 8-30
collect() function, gc module, 6-45
collections module, 4-60
Colon, and indentation, 1-37
COM, 12-33, 12-34
COM, example of controlling Microsoft Word, 12-38
COM, launching Microsoft Word, 12-36
Command line arguments, manual parsing, 4-29
Command line options, 4-28
Command line options, parsing with optparse, 4-30
Command line, running Python, 1-24
Comments, 1-32, 7-3
Comments, vs. documentation strings, 7-3
Community links, 1-2
Compiling regular expressions, 9-13
Complex type, 1-46
complex() function, 4-25
Computed attributes, 6-33, 6-36, 6-37
Concatenation of strings, 1-59
Concatenation, lists, 1-67
Concatenation, of sequences, 2-30
Conditionals, 1-39
ConfigParser module, 4-48
Conformance checking of functions, 3-41
Container, 2-17
Containers, dictionary, 2-19
Containers, list, 2-18
__contains__() method, 5-25
continue statement, 2-36
Contract programming, 7-21
Conversion of numbers, 1-55
Converting to strings, 1-64
copy module, 2-68, 4-35
copy() function, copy module, 4-35
copy() function, shutil module, 4-42
Copying and moving files, 4-42
copytree() function, shutil module, 4-42
cos() function, math module, 1-54
cPickle module, 4-44
Creating new objects, 5-4
Creating programs, 1-19
ctime() function, time module, 4-41
ctypes direct I/O support, 10-22
ctypes library, 10-17
ctypes module, and C++, 12-30
ctypes module, example of, 12-25
ctypes module, limitations of, 12-29
ctypes module, specifying type signatures, 12-27
ctypes module, supported datatypes, 12-28
ctypes modules, 12-23
ctypes, creating a C datatype instance, 10-19
ctypes, creating arrays, 10-20
ctypes, list of datatypes, 10-18
ctypes, structures, 10-21

D

Data interchange, 12-4
Data structure, dictionary, 6-3
Data structures, 2-5
Database like queries on lists, 2-55
Database, interface to, 4-61
Database, SQL injection attack risk, 4-63
Datatypes, in library modules, 4-57
Date and time manipulation, 4-59
datetime module, 4-59
Debugger, 7-27
Debugger, breakpoint, 7-29, 7-31
Debugger, commands, 7-29
Debugger, launching inside a program, 7-28
Debugger, listing source code, 7-31
Debugger, running at command line, 7-33
Debugger, running functions, 7-32
Debugger, single step execution, 7-32
Debugger, stack trace, 7-30
__debug__ variable, 7-23
decimal module, 4-58
Declarative programming, 2-58
Deep copies, 2-68
deepcopy() function, copy module, 2-68, 4-35
def statement, 1-76, 3-8
Defining a function, 3-8
Defining new functions, 1-76
Defining new objects, 5-4
Definition order, 3-7
del operator, lists, 1-70
delattr() function, 5-31
Deleting items from dictionary, 2-14
__delitem__() method, 5-24
__del__() method, 6-46, 6-47
deque object, collections module, 4-60
Derived class, 5-11
Design by contract, 7-21
Destruction of objects, 6-43
Dictionary, 2-13
Dictionary, and class representation, 6-9
Dictionary, and local function variables, 6-4
Dictionary, and module namespace, 6-5
Dictionary, and object representation, 6-6
Dictionary, creating from list of tuples, 2-21
Dictionary, persistent, 4-46
Dictionary, testing for keys, 2-20
Dictionary, updating and deleting, 2-14
Dictionary, use as a container, 2-19
Dictionary, use as data structure, 6-3
Dictionary, using as function keyword arguments, 3-40
Dictionary, when to use, 2-15
__dict__ attribute, of instances, 6-7, 6-8
__dict__ variable, of modules, 4-14
dir() function, 1-81, 1-82
direct I/O, with ctypes objects', 10-22
Directory listing, 4-38
disable() function, gc module, 6-45
divmod() function, 1-50, 1-54, 4-24
__div__() method, 5-26
doctest module, 3-48, 7-7, 7-8
doctest module, self-testing, 7-10
Documentation, 1-17
Documentation strings, 3-46, 7-3
Documentation strings, and help() command, 7-6
Documentation strings, and help() function, 3-47
Documentation strings, and IDEs, 7-5
Documentation strings, and testing, 3-48, 7-7
Documentation strings, vs. comments, 7-3
Double precision float, 1-52
Double-quoted string, 1-56
Downloads, 1-2
dumps() function, pickle module, 4-45
Duplicating containers, 2-66

E

easy_install command, 4-71
Edit,compile,debug cycle, 1-13
Eggs, Python package format, 4-71
ElementTree module, xml.etree package, 12-7
elif statement, 1-39
else statement, 1-39
Embedded nulls in strings, 1-58
empty code blocks, 1-42
enable() function, gc module, 6-45
Enabling future features, 1-51
Encapsulation, 6-24
Encapsulation, and accessor methods, 6-30
Encapsulation, and properties, 6-31
Encapsulation, challenges of, 6-25
Encapsulation, uniform access principle, 6-35
end() method, of Match objects, 9-16
endswith() method, strings, 1-62
enumerate() function, 2-39, 2-40, 4-26
environ variable, os module, 4-37
Environment variables, 4-37
Error reporting strategy in exceptions, 3-57
Escape codes, strings, 1-57
Event loop, and GUI programming, 4-54
except statement, 1-79, 3-50
Exception base class, 5-28
Exception, defining new, 5-28
Exception, printing tracebacks, 7-25
Exception, uncaught, 7-24
Exceptions, 1-78, 3-50
Exceptions, catching, 1-79
Exceptions, catching any, 3-55
Exceptions, catching multiple, 3-54
Exceptions, caution on use, 3-56
Exceptions, finally statement, 3-58
Exceptions, how to report errors, 3-57
Exceptions, ignoring, 3-55
Exceptions, list of built-in, 3-52
Exceptions, passed value, 3-53
Exceptions, propagation of, 3-51
Executing system commands, 11-5, 11-8
Execution model, 1-31
Execution of modules, 4-5
exists() function, os.path module, 4-40
exit() function, sys module, 3-59
Exploding heads, and exceptions, 3-56
Exponential notation, 1-52
Extended slicing of sequences, 2-32

F

False Value, 1-47
File globbing, 4-38
File system, copying and moving files, 4-42
File system, getting a directory listing, 4-38
File tests, 4-40
File, binary, 10-9
File, obtaining metadata, 4-41
Files, and for statement, 1-73
Files, opening, 1-72
Files, reading line by line, 1-73
__file__ attribute, of modules, 4-7
Filtering sequence data, 2-53
finally statement, 3-58
find() method of strings, 9-6
find() method, strings, 1-62
Finding a substring, 9-6
finditer() method, of regular expressions, 9-19
First class objects, 2-69
Float type, 1-46, 1-52
float() function, 1-55, 4-25
Floating point numbers, 1-52
Floating point, accuracy, 1-53
Floor division operator, 1-51
__floordiv__() method, 5-26
For loop, and tuples, 2-41
For loop, keeping a loop counter, 2-39
for statement, 2-34
for statement, and files, 1-73
for statement, and generators, 8-17
for statement, and iteration, 8-3
for statement, internal operation of, 8-4
for statement, iteration variable, 2-35
Format codes, string formatting, 2-26
Format codes, struct module, 10-12
format() method of strings, 9-31
Formatted output, 2-24
format_exc() function, traceback module, 7-25
from module import *, 4-18
from statement, 4-17
from __future__ import, 1-51
Function, and generators, 8-17
Function, running in debugger, 7-32
Functions, 3-8, 3-9
Functions, accepting any combination of arguments, 3-39
Functions, anonymous with lambda, 3-45
Functions, argument passing, 3-15
Functions, benefits of using, 3-8
Functions, Bottom-up style, 3-11
Functions, calling with positional arguments, 3-17
Functions, checking of return statement, 3-43
Functions, conformance checking, 3-41
Functions, default arguments, 3-16
Functions, defining, 1-76
Functions, definition order, 3-10
Functions, design of, 3-14
Functions, design of and global variables, 3-32
Functions, design of and side effects, 3-26
Functions, design of and transformation of inputs, 3-22
Functions, design of argument names, 3-20
Functions, design of input arguments, 3-21
Functions, documentation strings, 3-46
Functions, global variables, 3-29, 3-30
Functions, keyword arguments, 3-18
Functions, local variables, 3-28
Functions, mixing positional and keyword arguments, 3-19
Functions, multiple return values, 3-24
Functions, overloading (lack of), 3-12
Functions, side effects, 3-25
Functions, tuple and dictionary expansion, 3-40
Functions, variable number of arguments, 3-35, 3-36, 3-37, 3-38

G

Garbage collection, and cycles, 6-44, 6-45
Garbage collection, and __del__() method, 6-46, 6-47
Garbage collection, reference counting, 6-43
gc module, 6-45
Generating text, 9-23
Generator, 8-17, 8-18
Generator expression, 8-24, 8-25
Generator expression, efficiency of, 8-27
Generator tricks presentation, 8-33
Generator vs. iterator, 8-22
Generator, and code reuse, 8-30
Generator, and StopIteration exception, 8-20
Generator, example of following a file, 8-21
Generator, use of, 8-29
getatime() function,, 4-41
getattr() function, 5-31
__getitem__() method, 5-24
getmtime() function, os.path module, 4-41
getoutput() function, commands module, 11-5
getsize() function, os.path module, 4-41
Getting a list of symbols, 1-81
Getting started, 1-8
glob module, 4-38
global statement, 3-31
Global variables, 3-27, 4-6
Global variables, accessing in functions, 3-29
Global variables, modifying inside a function, 3-30
group() method, of Match objects, 9-16
Groups, extracting text from in regular expressions, 9-18
Groups, in regular expressions, 9-17
GUI programming, event loop model, 4-54
GUI programming, with Tkinter, 4-51
Guido van Rossum, 1-3

H

hasattr() function, 5-31
Hash table, 2-13
Haskell, 1-5
Haskell, list comprehension, 2-56
has_key() method, of dictionaries, 2-20
Heavy wizardry, 6-42
help() command, 1-17
help() command, and documentation strings, 7-6
help() function, and documentation strings, 3-47
hex() function, 4-25
HTTP, simple web server, 12-18

I

I/O redirection, subprocess module, 11-21
Identifiers, 1-33
IDLE, 1-10, 1-11, 1-16
IDLE, creating new program, 1-20, 1-21
IDLE, on Mac or Unix, 1-12
IDLE, running programs, 1-23
IDLE, saving programs, 1-22
IEEE 754, 1-52
if statement, 1-39
Ignoring an exception, 3-55
Immutable objects, 1-63
import statement, 1-77, 4-3
import statement, creation of .pyc and .pyo files, 4-11
import statement, from modifier, 4-17
import statement, importing all symbols, 4-18
import statement, proper use of namespaces, 4-20
import statement, repeated, 4-8
import statement, search path, 4-9, 4-10
import statement, supported file types, 4-11
import, as modifier, 4-15
import, use in extensible programs, 4-16
importing different versions of a library, 4-16
in operator, 5-25
in operator, dictionary, 2-20
in operator, lists, 1-69
in operator, strings, 1-60
Indentation, 1-36, 1-37
Indentation style, 1-38
index() method, strings, 1-62
Indexing of lists, 1-68
Infinite data streams, 8-31
Inheritance, 5-11, 5-14
Inheritance example, 5-13
Inheritance, and object base, 5-16
Inheritance, and polymorphism, 5-19
Inheritance, and __init__() method, 5-17
Inheritance, implementation of, 6-19, 6-21
Inheritance, multiple, 5-20, 6-23
Inheritance, multiple inheritance, 6-22
Inheritance, organization of objects, 5-15
Inheritance, redefining methods, 5-18
Inheritance, uses of, 5-12
INI files, parsing of, 4-48
Initialization of objects, 5-6
__init__() method, 6-41
__init__() method in classes, 5-6
__init__() method, and inheritance, 5-17
insert() method, of lists, 1-67
Inspecting modules, 1-81
Inspecting objects, 1-82
Instance data, 5-7
Instances, and __class__ attribute, 6-10
Instances, creating new, 5-5
Instances, modifying after creation, 6-15
Instances, representation of, 6-7, 6-8
int() function, 1-55, 4-25
Integer division, 1-51
Integer type, 1-46
Integer type, operations, 1-50
Integer type, precision of, 1-48
Integer type, promotion to long, 1-49
Interactive mode, 1-13, 1-14, 1-15
Interactive subprocesses, 11-24
Interpreter execution, 11-3
Interpreter prompts, 1-15
__invert__() method, 5-26
IronPython, 12-45
is operator, 2-62, 2-64
isalpha() method, strings, 1-62
isdigit() method, strings, 1-62
isdir() function, os.path module, 4-39, 4-40
isfile() function, os.path module, 4-39, 4-40
isinstance() function, 2-71
islower() method, strings, 1-62
Item access methods, 5-24
Iterating over a sequence, 2-34
Iteration, 8-3
Iteration protocol, 8-4
Iteration variable, for loop, 2-35
Iteration, design of iterator classes, 8-14
Iteration, user defined, 8-8, 8-9
Iterator vs. generator, 8-22
itertools module, 8-32
__iter__() method, 8-4

J

Java, and Jython, 12-41
join() function, os.path module, 4-39
join() method, of strings, 9-25
join() method, strings, 1-62
Jython, 12-41

K

key argument of sort() method, 2-48
KeyboardInterrupt exception, 3-59
Keys, dictionary, 2-13
Keyword arguments, 3-18
Keywords, 1-34, 1-35
kill()function, os module, 11-15

L

lambda statement, 3-45
Lazy evaluation, 8-31
len() function, 2-29, 5-24
len() function, lists, 1-69
len() function, strings, 1-60
__len__() method, 5-24
Library modules, 1-77
Life cycle of objects, 6-40
Line continuation, 1-43
Lisp, 1-5
List, 2-29
List comprehension, 2-52, 2-53, 2-54
List comprehension uses, 2-55
List comprehensions and awk, 2-57
List concatenation, 1-67
List processing, 2-51
List replication, 1-69
List type, 1-67
List vs. Tuple, 2-12
list() function, 2-66, 2-67
List, extra memory overhead, 2-12
List, Looping over items, 2-34
List, sorting, 2-46
List, use as a container, 2-18
listdir() function, os module, 4-38
lists vs. arrays, 10-28
Lists, changing elements, 1-68
Lists, indexing, 1-68
Lists, removing items, 1-70
Lists, searching, 1-69
loads() function, pickle module, 4-45
Local variables, 3-27
Local variables in functions, 3-28
log() function, math module, 1-54
Long type, 1-46, 1-49
Long type, use with integers, 1-49
long() function, 1-55, 4-25
Looping over integers, 2-37
Looping over items in a sequence, 2-34
Looping over multiple sequences, 2-42
lower() method, strings, 1-61, 1-62
__lshift__() method, 5-26
lstrip() method, of strings, 9-5

M

Main program, 4-7
main() function, unittest module, 7-16
__main__, 4-7
__main__ module, 7-10
Match objects, re module, 9-16
match() method, of regular expression patterns, 9-14
Matching a regular expression, 9-14
math module, 1-54, 1-77, 4-33
Math operators, 5-26
Math operators, floating point, 1-54
Math operators, integer, 1-50
max() function, 2-33, 4-24
Memory efficiency, and generators, 8-31
Memory management, reference counting, 2-62, 2-64
Memory use of tuple and list, 2-12
Method invocation, 5-29
Method, definition of, 5-3
Methods, calling other methods in the same class, 5-9
Methods, in classes, 5-8
Methods, private, 6-28
min() function, 2-33, 4-24
Modules, 4-3
modules variable, sys module, 4-8
Modules, as object, 4-13
Modules, dictionary, 4-14
Modules, execution of, 4-5
Modules, loading of, 4-8
Modules, namespaces, 4-4
Modules, search path, 4-9, 4-10
Modules, self-testing with doctest, 7-10
__mod__() method, 5-26
move() function, shutil module, 4-42
__mro__ attribute, of classes, 6-23
Multiple inheritance, 5-20, 6-22, 6-23
__mul__() method, 5-26

N

Namespace, 4-14
Namespaces, 4-4, 4-20
__name__ attribute, of modules, 4-7
Naming conventions, Python's reliance upon, 6-26
Negative indices, lists, 1-68
__neg__() method, 5-26
Network programming introduction, 12-15
Network programming, example of sockets, 12-16
__new__() method, 6-41, 6-42
next() method, and iteration, 8-4
next() method, of generators, 8-19
no-op statement, 1-42
None type, 2-4
None type, returned by functions, 3-23
not operator, 1-40
Null value, 2-4
Numeric conversion, 1-55
Numeric datatypes, 1-46
numpy, 10-29

O

object base class, 5-16
Object oriented programming, 5-3
Object oriented programming, and encapsulation, 6-24
Objects, attribute binding, 6-17, 6-20
Objects, attributes of, 5-7
Objects, creating containers, 5-24
Objects, creating new instances, 5-5
Objects, creating private attributes, 6-27
Objects, creation steps, 6-41
Objects, defining new, 5-4
Objects, first class behavior, 2-69
Objects, inheritance, 5-11
Objects, invoking methods, 5-5
Objects, life cycle, 6-40
Objects, making a deep copy of, 2-68
Objects, memory management of, 6-43
Objects, method invocation, 5-29
Objects, modifying attributes of instances, 6-13
Objects, modifying instances, 6-15
Objects, multiple inheritance, 6-22
Objects, reading attributes, 6-16
Objects, representation of, 6-11
Objects, representation of instances, 6-7, 6-8
Objects, representation with dictionary, 6-6
Objects, saving with pickle, 4-44
Objects, serializing into a string, 4-45
Objects, single inheritance, 6-21
Objects, special methods, 5-22
Objects, type checking, 2-71
Objects, type of, 2-63
oct() function, 4-25
Old-style classes, 5-16
Online help, 1-17
open() function, 1-72
open() function, shelve module, 4-46, 4-47
Optimized mode, 7-23
Optimized mode (-O), 7-22
Optional features, defining function with, 3-18
Optional function arguments, 3-16
optparse module, 4-30
or operator, 1-40
ord() function, 4-25
__or__() method, 5-26
os module, 4-36, 11-6
os.path module, 4-39, 4-41
Output, print statement, 1-41
Overloading, lack of with functions, 3-12

P

pack() function, struct module, 10-11
Packing binary structures, 10-10, 10-11
Packing values into a tuple, 2-9
Parallel iteration, 2-42
Parsing, 9-3
pass statement, 1-42
path variable, sys module, 4-9, 4-10
Pattern syntax, regular expressions, 9-11
pdb module, 7-27
pdb module, commands, 7-29
Performance of string operations, 9-8
Performance statistics, profile module, 7-34
Perl, difference in string handling, 1-75
Perl, regular expressions and Python, 9-21
Perl, string interpolation and Python, 9-28
Persistent dictionary, 4-46
pexpect library, 11-24
pickle module, 4-44
pickle module, and strings, 4-45
Pipelines, and generators, 8-29
Pipes, subprocess module, 11-18
poll() method, Popen objects, 11-14
Polymorphism, and inheritance, 5-19
Popen() function, subprocess module, 11-8
popen2 module, 11-6
Positional function arguments, 3-17
Post-assertion, 7-21
pow() function, 1-50, 1-54, 4-24
Powers of numbers, 1-50
__pow__() method, 5-26
Pre-assertion, 7-21
Primitive datatypes, 2-3
print statement, 1-41, 4-32, 5-23
print statement, and files, 1-72
print statement, and str(), 1-64
print statement, trailing comma, 1-41
print, formatted output, 2-25
print_exc() function, traceback module, 7-25
Private attributes, 6-27
Private attributes, performance of name mangling, 6-29
Private methods, 6-28
profile module, 7-34
Profiling, 7-34
Program exit, 3-59
Program structure, 3-6
Program structure, definition order, 3-7
Propagation of exceptions, 3-51
Properties, and encapsulation, 6-31
py files, 1-19
Python Documentation, 1-17
Python eggs packages, 4-71
Python influences, 1-5
Python interpreter, 1-13
Python interpreter, keeping alive after execution, 7-26
Python interpreter, optimized mode, 7-22, 7-23
Python package index, 4-67
Python, extending with ctypes, 12-23
Python, reason created, 1-4
Python, running on command line, 1-24
Python, source files, 1-19
Python, starting on Mac, 1-12
Python, starting on Unix, 1-12
Python, starting on Windows, 1-11
Python, starting the interpreter, 1-9
Python, statement execution, 1-31
Python, uses of, 1-6, 1-7
Python, year created, 1-3
python.org website, 1-2
Pythonwin extension, 12-33, 12-34

R

raise Statement, 1-80
raise statement, 3-50
Raising exceptions, 1-80
random module, 4-34
Random numbers, 4-34
range() function, 2-38, 4-26
range() vs. xrange(), 2-38
Raw strings, 1-57
Raw strings, and regular expressions, 9-12
re module, 9-10
re module, compile() function, 9-13
re module, find all occurrences of a pattern, 9-19
re module, pattern syntax, 9-11
Read-eval loop, 1-14
Reading attributes on objects, 6-16
readline() method, files, 1-72
Redefining methods with inheritance, 5-18
Redefining output file, 4-32
Redirecting print to a file, 1-72
Reference counting, 2-62, 2-64, 2-67, 6-43
Reference counting, containers, 2-66
register_function() method, of SimpleXMLRPCServer, 12-21
register_instance() method, of SimpleXMLRPCServer, 12-21
Regular expression syntax, 9-11
Regular expressions (see re), 9-10
Regular expressions, and Perl, 9-21
Regular expressions, compiling patterns, 9-13
Regular expressions, extracting text from numbered groups, 9-18
Regular expressions, Match objects, 9-16
Regular expressions, matching, 9-14
Regular expressions, numbered groups, 9-17
Regular expressions, obtaining matching text, 9-16
Regular expressions, pattern replacement, 9-20
Regular expressions, searching, 9-15
Relational database, interface to, 4-61
Relational operators, 1-40
remove() method, lists, 1-70
Repeated function definitions, 3-12
Repeated imports, 4-8
replace() method of strings, 9-7
replace() method, strings, 1-61, 1-62
Replacing a substring, 9-7
Replacing text, 1-61
Replication of sequences, 2-30
repr() function, 4-25, 5-23
Representation of strings, 1-58
representing binary data, 10-6
__repr__() method, 5-23
Reserved names, 1-34, 1-35
return statement, 3-23
return statement, multiple values, 3-24
returncode attribute, Popen objects, 11-13
reversed() function, 4-26
rfind() method, strings, 1-62
rindex() method, strings, 1-62
rmtree() function, shutil module, 4-42
round() function, 4-24
Rounding errors, floating point, 1-53
__rshift__() method, 5-26
rsplit() method of strings, 9-4
rstrip() method, of strings, 9-5
Ruby, string interpolation and Python, 9-28
run() function, pdb module, 7-33
runcall() function, pdb module, 7-33
runeval() function, pdb module, 7-33
Running Python, 1-9
Runtime error vs. compile-time error, 3-42

S

safe_substitute() method, of Template objects, 9-30
Sample Python program, 1-26
Scope of iteration variable in loops, 2-35
Scripting, 3-3
Scripting language, 1-3
Scripting, defined, 3-4
Scripting, problem with, 3-5
search() method, of regular expression patterns, 9-15
Searching for a regular expression, 9-15
self parameter of methods, 5-7, 5-8
Sequence, 2-29
Sequence sorting, 2-49
Sequence, concatenation, 2-30
Sequence, extended slicing, 2-32
Sequence, indexing, 2-29
Sequence, length, 2-29
Sequence, looping over items, 2-34
Sequence, replication, 2-30
Sequence, slicing, 2-31
Sequence, string, 1-58
Serializing objects into strings, 4-45
Set theory, list comprehension, 2-56
Set type, 2-22
set() function, 2-22
setattr() function, 5-31
__setitem__() method, 5-24
setUp() method, unittest module, 7-17
setup.py file, third party modules, 4-70
setuptools module, 4-71
set_trace() function, pdb module, 7-28
Shallow copy, 2-67
Shell operations, 4-42
shelve module, 4-46
shutil module, 4-42
Side effects, 3-25
SimpleHTTPServer module, 12-18
SimpleXMLRPCServer module, 12-20
sin() function, math module, 1-54
Single-quoted string, 1-56
Single-step execution, 7-32
Slicing operator, 2-31
__slots__ attribute of classes, 6-38
socket module, example of, 12-16
SocketServer module, example of, 12-17
sort() method of lists, 3-44
sort() method, of lists, 2-46, 2-48
sorted() function, 2-49, 4-26
Sorting lists, 2-46
Sorting with a key function, 2-48
Sorting, of any sequence, 2-49
Source files, 1-19
Source files, and modules, 4-3
Source listing, in debugger, 7-31
span) method, of Match objects, 9-16
Special methods, 1-82, 5-22
split() method, of strings, 9-4
split() method, strings, 1-62, 1-66
Splitting strings, 9-4
Splitting text, 1-66
SQL queries , how to form, 4-63
SQL queries, injection attack risk, 4-63
SQL queries, value substitutions in, 4-65
sqlite3 module, 4-62
sqrt() function, math module, 1-54
Stack trace, in debugger, 7-30
Standard I/O streams, 4-32
Standard library, 4-22
start() method, of Match objects, 9-16
startswith() method, strings, 1-62
Statements, 1-31, 3-6
Status codes, subprocesses, 11-12
stderr variable, sys module, 4-32
stdin variable, sys module, 4-32
stdout variable, sys module, 4-32
StopIteration exception, 8-5
StopIteration exception, and generators, 8-20
str() function, 1-64, 4-25, 5-23
String concatenation, performance of, 9-24
String format codes, 2-26
String formatting, 2-25
String formatting, with dictionary, 2-27, 9-29
String interpolation, 2-27, 9-28
String joining, 9-25
String joining vs. concatenation, 9-26
String manipulation, performance of, 9-8
String replacement, 9-7
String searching, 9-6
String splitting, 9-4
String stripping, 9-5
String templates, 9-30
String type, 2-29
StringIO objects, 9-27
Strings, concatenation, 1-59
Strings, conversion to, 1-64
Strings, conversion to numbers, 1-55, 1-75
Strings, escape codes, 1-56, 1-57
Strings, immutability, 1-63
Strings, indexing, 1-59
Strings, length of, 1-60
Strings, literals, 1-56
Strings, methods, 1-61, 1-62
Strings, raw strings, 1-57
Strings, redirecting I/O to, 9-27
Strings, replication, 1-60
Strings, representation, 1-58
Strings, searching for substring, 1-60
Strings, slicing, 1-59
Strings, splitting, 1-66
Strings, triple-quoted, 1-56
Strings, use of raw strings, 9-12
strip() method, of strings, 9-5
strip() method, strings, 1-61, 1-62
Stripping characters, 1-61
Stripping characters from strings, 9-5
struct module, 10-11
struct module, format modifiers, 10-13
struct module, packing codes, 10-12
structures, creating with ctypes, 10-21
sub() method of regular expression patterns, 9-20
Subclass, 5-11
Subprocess, 11-4
subprocess module, 11-6, 11-7
subprocess module, capturing output, 11-17
subprocess module, capturing stderr, 11-20
subprocess module, changing the working directory, 11-11
subprocess module, collecting return codes, 11-13
subprocess module, I/O redirection, 11-21
subprocess module, interactive subprocesses, 11-24
subprocess module, pipes, 11-18
subprocess module, polling, 11-14
subprocess module, sending/receiving data, 11-18
subprocess module, setting environment variables, 11-10
Subprocess status code, 11-12
subprocess, killing with a signal, 11-15
substitute() method, of Template objects, 9-30
__sub__() method, 5-26
sum() function, 2-33, 4-24
Superclass, 5-11
Swig, 12-31
sys module, 4-27
System commands, executing as subprocess, 11-8
system() function, os module, 4-36, 11-5
SystemExit exception, 3-59

T

tan() function, math module, 1-54
TCP, server example, 12-16
tearDown() method, unittest module, 7-17
Template strings, 9-30
TestCase class, of unittest module, 7-13
Testing files, 4-40
testmod() function, doctest module, 7-8
Text parsing, 9-3
Text replacement, 1-61
Text strings, 1-58
Third party modules, 4-67, 4-68
Third party modules, and C/C++ code, 4-72
Third party modules, eggs format, 4-71
Third party modules, native installer, 4-69
Third party modules, setup.py file, 4-70
time module, 4-41
Tkinter module, 4-51
Tkinter module, sample widgets, 4-53
traceback module, 7-25
Traceback, uncaught exception, 7-24
Tracebacks, 1-80
Triple-quoted string, 1-56
True value, 1-47
Truncation, integer division, 1-51
Truth values, 1-40
try statement, 1-79, 3-50
Tuple, 2-6, 2-29
Tuple vs. List, 2-12
Tuple, immutability of, 2-8
Tuple, packing values, 2-9
Tuple, unpacking in for-loop, 2-41
Tuple, unpacking values, 2-10
Tuple, use of, 2-7
Tuple, using as function arguments, 3-40
Type checking, 2-71
Type conversion, 1-75
Type of objects, 2-63
type() function, 2-63, 2-71
typecodes, array module, 10-25
Types, 1-33
Types, numeric, 1-46
Types, primitive, 2-3

U

Unbound method, 5-30
Uniform access principle, 6-35
Unit testing, 7-12
unittest module, 7-12, 7-13
unittest module, example of, 7-14
unittest module, running tests, 7-16
unittest module, setup and teardown, 7-17
unpack() function, struct module, 10-11
Unpacking binary structures, 10-10, 10-11
Unpacking values from tuple, 2-10
upper() method, strings, 1-61, 1-62
urllib module, 1-77
urlopen() function, urllib module, 1-77
User-defined exceptions, 5-28

V

Value of exceptions, 3-53
Variable assignment, 2-61, 2-65
Variable assignment, assignment of globals in function, 3-31
Variable assignment, global vs. local, 3-27
Variable number of function arguments, 3-35, 3-36, 3-37, 3-38
Variables, and modules, 4-6
Variables, examining in debugger, 7-30
Variables, names of, 1-33
Variables, reference counting, 2-62, 2-64
Variables, scope in functions, 3-28, 3-29
Variables, type of, 1-33
vars() function, 9-29

W

wait() method, Popen objects, 11-13
walk() function, os module, 4-36
Walking a directory of files, 4-36
while statement, 1-36
Widgets, and Tkinter, 4-53
Windows, binary files, 10-9
Windows, killing a subprocess, 11-15
Windows, starting Python, 1-11
write() method, files, 1-72

X

XML overview, 12-5
XML parsing, extracting document elements, 12-9
XML parsing, extracting element text, 12-11
XML parsing, getting element attributes, 12-12
XML, ElementTree module, 12-7
XML, parsing with ElementTree module, 12-8
XML-RPC, 12-19
XML-RPC, server example, 12-20
xmlrpclib module, 12-20
__xor__() method, 5-26
xrange() function, 2-37, 4-26
xrange() vs. range(), 2-38

Z

zip() function, 2-42, 2-43, 2-44, 4-26