| | Copyright |
| | Dedication |
| | Preface |
|
| | About This Second Edition |
|
| | Prerequisites |
|
| | This Book's Scope |
|
| | This Book's Style and Structure |
|
| | Book Updates |
|
| | Font Conventions |
|
| | About the Programs in This Book |
|
| | Using Code Examples |
|
| | How to Contact Us |
|
| | Acknowledgments |
|
| |
Part I:
Getting Started |
|
| |
Chapter 1.
A Python Q&A Session |
|
| |
Section 1.1.
Why Do People Use Python? |
|
| |
Section 1.2.
Is Python a Scripting Language? |
|
| |
Section 1.3.
Okay, But What's the Downside? |
|
| |
Section 1.4.
Who Uses Python Today? |
|
| |
Section 1.5.
What Can I Do with Python? |
|
| |
Section 1.6.
What Are Python's Technical Strengths? |
|
| |
Section 1.7.
How Does Python Stack Up to Language X? |
|
|
| |
Chapter 2.
How Python Runs Programs |
|
| |
Section 2.1.
Introducing the Python Interpreter |
|
| |
Section 2.2.
Program Execution |
|
| |
Section 2.3.
Execution Model Variations |
|
|
| |
Chapter 3.
How You Run Programs |
|
| |
Section 3.1.
Interactive Coding |
|
| |
Section 3.2.
System Command Lines and Files |
|
| |
Section 3.3.
Clicking Windows File Icons |
|
| |
Section 3.4.
Module Imports and Reloads |
|
| |
Section 3.5.
The IDLE User Interface |
|
| |
Section 3.6.
Other IDEs |
|
| |
Section 3.7.
Embedding Calls |
|
| |
Section 3.8.
Frozen Binary Executables |
|
| |
Section 3.9.
Text Editor Launch Options |
|
| |
Section 3.10.
Other Launch Options |
|
| |
Section 3.11.
Future Possibilities? |
|
| |
Section 3.12.
Which Option Should I Use? |
|
| |
Section 3.13.
Part I Exercises |
|
|
| |
Part II:
Types and Operations |
|
| |
Chapter 4.
Numbers |
|
| |
Section 4.1.
Python Program Structure |
|
| |
Section 4.2.
Why Use Built-in Types? |
|
| |
Section 4.3.
Numbers |
|
| |
Section 4.4.
Python Expression Operators |
|
| |
Section 4.5.
Numbers in Action |
|
| |
Section 4.6.
The Dynamic Typing Interlude |
|
|
| |
Chapter 5.
Strings |
|
| |
Section 5.1.
String Literals |
|
| |
Section 5.2.
Strings in Action |
|
| |
Section 5.3.
String Formatting |
|
| |
Section 5.4.
String Methods |
|
| |
Section 5.5.
General Type Categories |
|
|
| |
Chapter 6.
Lists and Dictionaries |
|
| |
Section 6.1.
Lists |
|
| |
Section 6.2.
Lists in Action |
|
| |
Section 6.3.
Dictionaries |
|
| |
Section 6.4.
Dictionaries in Action |
|
|
| |
Chapter 7.
Tuples, Files, and Everything Else |
|
| |
Section 7.1.
Tuples |
|
| |
Section 7.2.
Files |
|
| |
Section 7.3.
Type Categories Revisited |
|
| |
Section 7.4.
Object Generality |
|
| |
Section 7.5.
References Versus Copies |
|
| |
Section 7.6.
Comparisons, Equality, and Truth |
|
| |
Section 7.7.
Python's Type Hierarchies |
|
| |
Section 7.8.
Other Types in Python |
|
| |
Section 7.9.
Built-in Type Gotchas |
|
| |
Section 7.10.
Part II Exercises |
|
|
| |
Part III:
Statements and Syntax |
|
| |
Chapter 8.
Assignment, Expressions, and Print |
|
| |
Section 8.1.
Assignment Statements |
|
| |
Section 8.2.
Expression Statements |
|
| |
Section 8.3.
Print Statements |
|
|
| |
Chapter 9.
if Tests |
|
| |
Section 9.1.
if Statements |
|
| |
Section 9.2.
Python Syntax Rules |
|
| |
Section 9.3.
Truth Tests |
|
|
| |
Chapter 10.
while and for Loops |
|
| |
Section 10.1.
while Loops |
|
| |
Section 10.2.
break, continue, pass, and the Loop else |
|
| |
Section 10.3.
for Loops |
|
| |
Section 10.4.
Loop Variations |
|
|
| |
Chapter 11.
Documenting Python Code |
|
| |
Section 11.1.
The Python Documentation Interlude |
|
| |
Section 11.2.
Common Coding Gotchas |
|
| |
Section 11.3.
Part III Exercises |
|
|
| |
Part IV:
Functions |
|
| |
Chapter 12.
Function Basics |
|
| |
Section 12.1.
Why Use Functions? |
|
| |
Section 12.2.
Coding Functions |
|
| |
Section 12.3.
A First Example: Definitions and Calls |
|
| |
Section 12.4.
A Second Example: Intersecting Sequences |
|
|
| |
Chapter 13.
Scopes and Arguments |
|
| |
Section 13.1.
Scope Rules |
|
| |
Section 13.2.
The global Statement |
|
| |
Section 13.3.
Scopes and Nested Functions |
|
| |
Section 13.4.
Passing Arguments |
|
| |
Section 13.5.
Special Argument Matching Modes |
|
|
| |
Chapter 14.
Advanced Function Topics |
|
| |
Section 14.1.
Anonymous Functions: lambda |
|
| |
Section 14.2.
Applying Functions to Arguments |
|
| |
Section 14.3.
Mapping Functions Over Sequences |
|
| |
Section 14.4.
Functional Programming Tools |
|
| |
Section 14.5.
List Comprehensions |
|
| |
Section 14.6.
Generators and Iterators |
|
| |
Section 14.7.
Function Design Concepts |
|
| |
Section 14.8.
Function Gotchas |
|
| |
Section 14.9.
Part IV Exercises |
|
|
| |
Part V:
Modules |
|
| |
Chapter 15.
Modules: The Big Picture |
|
| |
Section 15.1.
Why Use Modules? |
|
| |
Section 15.2.
Python Program Architecture |
|
| |
Section 15.3.
How Imports Work |
|
|
| |
Chapter 16.
Module Coding Basics |
|
| |
Section 16.1.
Module Creation |
|
| |
Section 16.2.
Module Usage |
|
| |
Section 16.3.
Module Namespaces |
|
| |
Section 16.4.
Reloading Modules |
|
|
| |
Chapter 17.
Module Packages |
|
| |
Section 17.1.
Package Import Basics |
|
| |
Section 17.2.
Package Import Example |
|
| |
Section 17.3.
Why Use Package Imports? |
|
| |
Section 17.4.
A Tale of Three Systems |
|
|
| |
Chapter 18.
Advanced Module Topics |
|
| |
Section 18.1.
Data Hiding in Modules |
|
| |
Section 18.2.
Enabling Future Language Features |
|
| |
Section 18.3.
Mixed Usage Modes: __name__ and __main__ |
|
| |
Section 18.4.
Changing the Module Search Path |
|
| |
Section 18.5.
The import as Extension |
|
| |
Section 18.6.
Module Design Concepts |
|
| |
Section 18.7.
Module Gotchas |
|
| |
Section 18.8.
Part V Exercises |
|
|
| |
Part VI:
Classes and OOP |
|
| |
Chapter 19.
OOP: The Big Picture |
|
| |
Section 19.1.
Why Use Classes? |
|
| |
Section 19.2.
OOP from 30,000 Feet |
|
|
| |
Chapter 20.
Class Coding Basics |
|
| |
Section 20.1.
Classes Generate Multiple Instance Objects |
|
| |
Section 20.2.
Classes Are Customized by Inheritance |
|
| |
Section 20.3.
Classes Can Intercept Python Operators |
|
|
| |
Chapter 21.
Class Coding Details |
|
| |
Section 21.1.
The Class Statement |
|
| |
Section 21.2.
Methods |
|
| |
Section 21.3.
Inheritance |
|
| |
Section 21.4.
Operator Overloading |
|
| |
Section 21.5.
Namespaces: The Whole Story |
|
|
| |
Chapter 22.
Designing with Classes |
|
| |
Section 22.1.
Python and OOP |
|
| |
Section 22.2.
Classes as Records |
|
| |
Section 22.3.
OOP and Inheritance: "is-a" Relationships |
|
| |
Section 22.4.
OOP and Composition: "has-a" Relationships |
|
| |
Section 22.5.
OOP and Delegation |
|
| |
Section 22.6.
Multiple Inheritance |
|
| |
Section 22.7.
Classes Are Objects: Generic Object Factories |
|
| |
Section 22.8.
Methods Are Objects: Bound or Unbound |
|
| |
Section 22.9.
Documentation Strings Revisited |
|
| |
Section 22.10.
Classes Versus Modules |
|
|
| |
Chapter 23.
Advanced Class Topics |
|
| |
Section 23.1.
Extending Built-in Types |
|
| |
Section 23.2.
Pseudo-Private Class Attributes |
|
| |
Section 23.3.
"New Style" Classes in Python 2.2 |
|
| |
Section 23.4.
Class Gotchas |
|
| |
Section 23.5.
Part VI Exercises |
|
|
| |
Part VII:
Exceptions and Tools |
|
| |
Chapter 24.
Exception Basics |
|
| |
Section 24.1.
Why Use Exceptions? |
|
| |
Section 24.2.
Exception Handling: The Short Story |
|
| |
Section 24.3.
The try/except/else Statement |
|
| |
Section 24.4.
The try/finally Statement |
|
| |
Section 24.5.
The raise Statement |
|
| |
Section 24.6.
The assert Statement |
|
|
| |
Chapter 25.
Exception Objects |
|
| |
Section 25.1.
String-Based Exceptions |
|
| |
Section 25.2.
Class-Based Exceptions |
|
| |
Section 25.3.
General raise Statement Forms |
|
|
| |
Chapter 26.
Designing with Exceptions |
|
| |
Section 26.1.
Nesting Exception Handlers |
|
| |
Section 26.2.
Exception Idioms |
|
| |
Section 26.3.
Exception Design Tips |
|
| |
Section 26.4.
Exception Gotchas |
|
| |
Section 26.5.
Core Language Summary |
|
| |
Section 26.6.
Part VII Exercises |
|
|
| |
Part VIII:
The Outer Layers |
|
| |
Chapter 27.
Common Tasks in Python |
|
| |
Section 27.1.
Exploring on Your Own |
|
| |
Section 27.2.
Conversions, Numbers, and Comparisons |
|
| |
Section 27.3.
Manipulating Strings |
|
| |
Section 27.4.
Data Structure Manipulations |
|
| |
Section 27.5.
Manipulating Files and Directories |
|
| |
Section 27.6.
Internet-Related Modules |
|
| |
Section 27.7.
Executing Programs |
|
| |
Section 27.8.
Debugging, Testing, Timing, Profiling |
|
| |
Section 27.9.
Exercises |
|
|
| |
Chapter 28.
Frameworks |
|
| |
Section 28.1.
An Automated Complaint System |
|
| |
Section 28.2.
Interfacing with COM: Cheap Public Relations |
|
| |
Section 28.3.
A Tkinter-Based GUI Editor for Managing Form Data |
|
| |
Section 28.4.
Jython: The Felicitous Union of Python and Java |
|
| |
Section 28.5.
Exercises |
|
|
| |
Chapter 29.
Python Resources |
|
| |
Section 29.1.
Layers of Community |
|
| |
Section 29.2.
The Process |
|
| |
Section 29.3.
Services and Products |
|
| |
Section 29.4.
The Legal Framework: The Python Software Foundation |
|
| |
Section 29.5.
Software |
|
| |
Section 29.6.
Popular Third-Party Software |
|
| |
Section 29.7.
Web Application Frameworks |
|
| |
Section 29.8.
Tools for Python Developers |
|
|
| |
Part IX:
Appendixes |
|
| |
Appendix A.
Installation and Configuration |
|
| |
Section A.1.
Installing the Python Interpreter |
|
|
| |
Appendix B.
Solutions to Exercises |
|
| |
Section B.1.
Part I, Getting Started |
|
| |
Section B.2.
Part II, Types and Operations |
|
| |
Section B.3.
Part III, Statements and Syntax |
|
| |
Section B.4.
Part IV, Functions |
|
| |
Section B.5.
Part V, Modules |
|
| |
Section B.6.
Part VI, Classes and OOP |
|
| |
Section B.7.
Part VII, Exceptions and Tools |
|
| |
Section B.8.
Part VIII, The Outer Layers |
|
|
| | Colophon |
| | Index |