| |
| |
Introduction | |
| |
| |
Acknowledgments | |
| |
| |
| |
Getting Started | |
| |
| |
Why Write Larger Programs in Python? Running Python | |
| |
| |
Numbers | |
| |
| |
Lists, Strings, and Tuples | |
| |
| |
Logical Values | |
| |
| |
Dictionaries | |
| |
| |
Assignments | |
| |
| |
Garbage Collection | |
| |
| |
Operators | |
| |
| |
Wrap-Up | |
| |
| |
| |
Statements | |
| |
| |
Python Statements | |
| |
| |
Example: Word Count | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Modules and Packages | |
| |
| |
Importing Modules | |
| |
| |
Importing Names from Modules | |
| |
| |
Avoiding Namespace Pollution | |
| |
| |
Reloading Modules | |
| |
| |
Search Paths | |
| |
| |
Packages | |
| |
| |
Example Stack Module | |
| |
| |
Critique of Modules | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Objects and Classes | |
| |
| |
Instances and Classes | |
| |
| |
Class Declarations | |
| |
| |
Instances | |
| |
| |
Methods | |
| |
| |
Single Inheritance | |
| |
| |
Visibility | |
| |
| |
Explicit Initializer Chaining | |
| |
| |
Example: Set Implementation | |
| |
| |
Critique | |
| |
| |
Example: BaseTimer | |
| |
| |
Inheritance As Classification | |
| |
| |
Multiple Inheritance | |
| |
| |
Recapitulation of the Scope of Names | |
| |
| |
Testing Objects and Classes | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Object-Oriented Patterns | |
| |
| |
Concept of Design Patterns | |
| |
| |
Creational Patterns | |
| |
| |
Structural Patterns | |
| |
| |
Behavioral Patterns | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Functions | |
| |
| |
Parameter and Argument Lists | |
| |
| |
Three-Level Scopes | |
| |
| |
Functional Programming | |
| |
| |
Function Objects | |
| |
| |
Built-In Functions | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Input/Output | |
| |
| |
File Objects | |
| |
| |
Execution Environment | |
| |
| |
Other Useful Modules | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Sequences | |
| |
| |
Common Sequence Operations | |
| |
| |
Tuples | |
| |
| |
Lists | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Strings | |
| |
| |
String Literals | |
| |
| |
Strings as Sequences | |
| |
| |
String Methods | |
| |
| |
Example: Splitter | |
| |
| |
String Formatting: The % Operator | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Dictionaries | |
| |
| |
Dictionary Operations | |
| |
| |
Example: Union-Find Algorithm | |
| |
| |
Persistence and Databases | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Exceptions | |
| |
| |
Exception Classes | |
| |
| |
Minimal Exception Handling | |
| |
| |
Examining the Exception | |
| |
| |
Raising Exceptions | |
| |
| |
Tracebacks | |
| |
| |
Re-Raising Exceptions | |
| |
| |
Raise with Strings | |
| |
| |
Try-Except-Else | |
| |
| |
The Try-Finally Statement | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Types | |
| |
| |
Type Objects | |
| |
| |
Members and Methods | |
| |
| |
Numbers, Strings, Tuples, Lists, and Dictionaries | |
| |
| |
Modules | |
| |
| |
User-Defined Functions | |
| |
| |
Code Objects | |
| |
| |
Classes | |
| |
| |
Class Instances | |
| |
| |
User-Defined Methods | |
| |
| |
Built-In Functions and Methods | |
| |
| |
Slice | |
| |
| |
Xrange | |
| |
| |
File | |
| |
| |
Frame | |
| |
| |
Traceback | |
| |
| |
Example: Scopes | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Programs and Run-Time Compilation | |
| |
| |
Python Interpreter Startup | |
| |
| |
Run-Time Compilation | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Abstract Data Types and Special Methods | |
| |
| |
Special Methods | |
| |
| |
Methods for All Objects | |
| |
| |
Operators | |
| |
| |
Arithmetic Operators | |
| |
| |
Augmented Assignment | |
| |
| |
Rich Comparisons | |
| |
| |
Attribute Access | |
| |
| |
Function Call Method | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Abstract Container Data Types | |
| |
| |
Special Methods for Container ADTs | |
| |
| |
DEQueue | |
| |
| |
Multidimensional Arrays | |
| |
| |
Class Versions of Built-In Data Types | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Priority Queues | |
| |
| |
Priority Queue Operations | |
| |
| |
Priority Queue Implementation | |
| |
| |
Unique Elements | |
| |
| |
Critique | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Sets | |
| |
| |
Set Operations | |
| |
| |
Implementation | |
| |
| |
PureSet: A Protection Proxy | |
| |
| |
SetEnumeration | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Concurrency | |
| |
| |
Threads | |
| |
| |
Race Conditions | |
| |
| |
Locks and Mutual Exclusion | |
| |
| |
Monitor Pattern | |
| |
| |
Producer-Consumer | |
| |
| |
Deadlock | |
| |
| |
Example: Future | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Transactions | |
| |
| |
Shared Database Operations | |
| |
| |
Example: Dining Philosophers | |
| |
| |
Implementation of SharedDB | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Run Queues | |
| |
| |
Simple RunQueue | |
| |
| |
Implementing RunQueue | |
| |
| |
Detecting Termination of an Object on the RunQueue | |
| |
| |
TransactionQueue | |
| |
| |
Example of TransactionQueue: Dining Philosophers | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Regular Expressions | |
| |
| |
Overall Behavior of re Module | |
| |
| |
re Syntax | |
| |
| |
Functions in re Module | |
| |
| |
Pattern Objects | |
| |
| |
Match Objects | |
| |
| |
Other Modes | |
| |
| |
Other Methods and Functions | |
| |
| |
Example: Scanner | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Parser | |
| |
| |
Overview of the Process | |
| |
| |
Implementing a Calculator | |
| |
| |
Building a Tree | |
| |
| |
Wrap-Up | |
| |
| |
Exercises | |
| |
| |
| |
Wrap-Up | |
| |
| |
Contents | |
| |
| |
Software | |
| |
| |
Advice to the Reader | |
| |
| |
Appendix A | |
| |
| |
Index | |