| |
| |
Preface | |
| |
| |
| |
Getting Started | |
| |
| |
| |
A Python Q&A Session | |
| |
| |
Why Do People Use Python? | |
| |
| |
Is Python a Scripting Language? | |
| |
| |
Okay, But What's the Downside? | |
| |
| |
Who Uses Python Today? | |
| |
| |
What Can I Do with Python? | |
| |
| |
What Are Python's Technical Strengths? | |
| |
| |
How Does Python Stack Up to Language X? | |
| |
| |
| |
How Python Runs Programs | |
| |
| |
Introducing the Python Interpreter | |
| |
| |
Program Execution | |
| |
| |
Execution Model Variations | |
| |
| |
| |
How You Run Programs | |
| |
| |
Interactive Coding | |
| |
| |
System Command Lines and Files | |
| |
| |
Clicking Windows File Icons | |
| |
| |
Module Imports and Reloads | |
| |
| |
The IDLE User Interface | |
| |
| |
Other IDEs | |
| |
| |
Embedding Calls | |
| |
| |
Frozen Binary Executables | |
| |
| |
Text Editor Launch Options | |
| |
| |
Other Launch Options | |
| |
| |
Future Possibilities? | |
| |
| |
Which Option Should I Use? | |
| |
| |
Part I Exercises | |
| |
| |
| |
Types and Operations | |
| |
| |
| |
Numbers | |
| |
| |
Python Program Structure | |
| |
| |
Why Use Built-in Types? | |
| |
| |
Numbers | |
| |
| |
Python Expression Operators | |
| |
| |
Numbers in Action | |
| |
| |
The Dynamic Typing Interlude | |
| |
| |
| |
Strings | |
| |
| |
String Literals | |
| |
| |
Strings in Action | |
| |
| |
String Formatting | |
| |
| |
String Methods | |
| |
| |
General Type Categories | |
| |
| |
| |
Lists and Dictionaries | |
| |
| |
Lists | |
| |
| |
Lists in Action | |
| |
| |
Dictionaries | |
| |
| |
Dictionaries in Action | |
| |
| |
| |
Tuples, Files, and Everything Else | |
| |
| |
Tuples | |
| |
| |
Files | |
| |
| |
Type Categories Revisited | |
| |
| |
Object Generality | |
| |
| |
References Versus Copies | |
| |
| |
Comparisons, Equality, and Truth | |
| |
| |
Python's Type Hierarchies | |
| |
| |
Other Types in Python | |
| |
| |
Built-in Type Gotchas | |
| |
| |
Part II Exercises | |
| |
| |
| |
Statements and Syntax | |
| |
| |
| |
Assignment, Expressions, and Print | |
| |
| |
Assignment Statements | |
| |
| |
Expression Statements | |
| |
| |
Print Statements | |
| |
| |
| |
if Tests | |
| |
| |
if Statements | |
| |
| |
Python Syntax Rules | |
| |
| |
Truth Tests | |
| |
| |
| |
while and for Loops | |
| |
| |
while Loops | |
| |
| |
break, continue, pass, and the Loop else | |
| |
| |
for Loops | |
| |
| |
Loop Variations | |
| |
| |
| |
Documenting Python Code | |
| |
| |
The Python Documentation Interlude | |
| |
| |
Common Coding Gotchas | |
| |
| |
Part III Exercises | |
| |
| |
| |
Functions | |
| |
| |
| |
Function Basics | |
| |
| |
Why Use Functions? | |
| |
| |
Coding Functions | |
| |
| |
A First Example: Definitions and Calls | |
| |
| |
A Second Example: Intersecting Sequences | |
| |
| |
| |
Scopes and Arguments | |
| |
| |
Scope Rules | |
| |
| |
The global Statement | |
| |
| |
Scopes and Nested Functions | |
| |
| |
Passing Arguments | |
| |
| |
Special Argument Matching Modes | |
| |
| |
| |
Advanced Function Topics | |
| |
| |
Anonymous Functions: lambda | |
| |
| |
Applying Functions to Arguments | |
| |
| |
Mapping Functions Over Sequences | |
| |
| |
Functional Programming Tools | |
| |
| |
List Comprehensions | |
| |
| |
Generators and Iterators | |
| |
| |
Function Design Concepts | |
| |
| |
Function Gotchas | |
| |
| |
Part IV Exercises | |
| |
| |
| |
Modules | |
| |
| |
| |
Modules: The Big Picture | |
| |
| |
Why Use Modules? | |
| |
| |
Python Program Architecture | |
| |
| |
How Imports Work | |
| |
| |
| |
Module Coding Basics | |
| |
| |
Module Creation | |
| |
| |
Module Usage | |
| |
| |
Module Namespaces | |
| |
| |
Reloading Modules | |
| |
| |
| |
Module Packages | |
| |
| |
Package Import Basics | |
| |
| |
Package Import Example | |
| |
| |
Why Use Package Imports? | |
| |
| |
A Tale of Three Systems | |
| |
| |
| |
Advanced Module Topics | |
| |
| |
Data Hiding in Modules | |
| |
| |
Enabling Future Language Features | |
| |
| |
Mixed Usage Modes: __name__ and __main__ | |
| |
| |
Changing the Module Search Path | |
| |
| |
The import as Extension | |
| |
| |
Module Design Concepts | |
| |
| |
Module Gotchas | |
| |
| |
Part V Exercises | |
| |
| |
| |
Classes and OOP | |
| |
| |
| |
OOP: The Big Picture | |
| |
| |
Why Use Classes? | |
| |
| |
OOP from 30,000 Feet | |
| |
| |
| |
Class Coding Basics | |
| |
| |
Classes Generate Multiple Instance Objects | |
| |
| |
Classes Are Customized by Inheritance | |
| |
| |
Classes Can Intercept Python Operators | |
| |
| |
| |
Class Coding Details | |
| |
| |
The Class Statement | |
| |
| |
Methods | |
| |
| |
Inheritance | |
| |
| |
Operator Overloading | |
| |
| |
Namespaces: The Whole Story | |
| |
| |
| |
Designing with Classes | |
| |
| |
Python and OOP | |
| |
| |
Classes as Records | |
| |
| |
OOP and Inheritance: "is-a" Relationships | |
| |
| |
OOP and Composition: "has-a" Relationships | |
| |
| |
OOP and Delegation | |
| |
| |
Multiple Inheritance | |
| |
| |
Classes Are Objects: Generic Object Factories | |
| |
| |
Methods Are Objects: Bound or Unbound | |
| |
| |
Documentation Strings Revisited | |
| |
| |
Classes Versus Modules | |
| |
| |
| |
Advanced Class Topics | |
| |
| |
Extending Built-in Types | |
| |
| |
Pseudo-Private Class Attributes | |
| |
| |
"New Style" Classes in Python 2.2 | |
| |
| |
Class Gotchas | |
| |
| |
Part VI Exercises | |
| |
| |
| |
Exceptions and Tools | |
| |
| |
| |
Exception Basics | |
| |
| |
Why Use Exceptions? | |
| |
| |
Exception Handling: The Short Story | |
| |
| |
The try/except/else Statement | |
| |
| |
The try/finally Statement | |
| |
| |
The raise Statement | |
| |
| |
The assert Statement | |
| |
| |
| |
Exception Objects | |
| |
| |
String-Based Exceptions | |
| |
| |
Class-Based Exceptions | |
| |
| |
General raise Statement Forms | |
| |
| |
| |
Designing with Exceptions | |
| |
| |
Nesting Exception Handlers | |
| |
| |
Exception Idioms | |
| |
| |
Exception Design Tips | |
| |
| |
Exception Gotchas | |
| |
| |
Core Language Summary | |
| |
| |
Part VII Exercises | |
| |
| |
| |
The Outer Layers | |
| |
| |
| |
Common Tasks in Python | |
| |
| |
Conversions, Numbers, and Comparisons | |
| |
| |
Manipulating Strings | |
| |
| |
Data Structure Manipulations | |
| |
| |
Manipulating Files and Directories | |
| |
| |
Internet-Related Modules | |
| |
| |
Executing Programs | |
| |
| |
Debugging, Testing, Timing, Profiling | |
| |
| |
Exercises | |
| |
| |
| |
Frameworks | |
| |
| |
An Automated Complaint System | |
| |
| |
Interfacing with COM: Cheap Public Relations | |
| |
| |
A Tkinter-Based GUI Editor for Managing Form Data | |
| |
| |
Jython: The Felicitous Union of Python and Java | |
| |
| |
Exercises | |
| |
| |
| |
Python Resources | |
| |
| |
Layers of Community | |
| |
| |
The Process | |
| |
| |
Services and Products | |
| |
| |
The Legal Framework: The Python Software Foundation | |
| |
| |
Software | |
| |
| |
Popular Third-Party Software | |
| |
| |
Web Application Frameworks | |
| |
| |
Tools for Python Developers | |
| |
| |
| |
Appendixes | |
| |
| |
| |
Installation and Configuration | |
| |
| |
| |
Solutions to Exercises | |
| |
| |
Index | |