Cover image for Learning Python, 2nd Edition

Book description

Portable, powerful, and a breeze to use, Python is the popular open source object-oriented programming language used for both standalone programs and scripting applications. Python is considered easy to learn, but there's no quicker way to mastery of the language than learning from an expert teacher. This edition of Learning Python puts you in the hands of two expert teachers, Mark Lutz and David Ascher, whose friendly, well-structured prose has guided many a programmer to proficiency with the language. Learning Python, Second Edition, offers programmers a comprehensive learning tool for Python and object-oriented programming. Thoroughly updated for the numerous language and class presentation changes that have taken place since the release of the first edition in 1999, this guide introduces the basic elements of the latest release of Python 2.3 and covers new features, such as list comprehensions, nested scopes, and iterators/generators. Beyond language features, this edition of Learning Python also includes new context for less-experienced programmers, including fresh overviews of object-oriented programming and dynamic typing, new discussions of program launch and configuration options, new coverage of documentation sources, and more. There are also new use cases throughout to make the application of language features more concrete. The first part of Learning Python gives programmers all the information they'll need to understand and construct programs in the Python language, including types, operators, statements, classes, functions, modules and exceptions. The authors then present more advanced material, showing how Python performs common tasks by offering real applications and the libraries available for those applications. Each chapter ends with a series of exercises that will test your Python skills and measure your understanding. Learning Python, Second Edition is a self-paced book that allows readers to focus on the core Python language in depth. As you work through the book, you'll gain a deep and complete understanding of the Python language that will help you to understand the larger application-level examples that you'll encounter on your own. If you're interested in learning Python--and want to do so quickly and efficiently--then Learning Python, Second Edition is your best choice.

Table of Contents

  1. Learning Python, 2nd Edition
  2. Dedication
  3. A Note Regarding Supplemental Files
  4. Preface
    1. About This Second Edition
    2. Prerequisites
    3. This Book's Scope
    4. This Book's Style and Structure
      1. Core Language
      2. Outer Layers
      3. Appendixes
    5. Book Updates
    6. Font Conventions
    7. About the Programs in This Book
    8. Using Code Examples
    9. How to Contact Us
    10. Acknowledgments
      1. Mark Also Says:
      2. David Also Says:
  5. I. Getting Started
    1. 1. A Python Q&A Session
      1. 1.1. Why Do People Use Python?
        1. 1.1.1. Software Quality
        2. 1.1.2. Developer Productivity
      2. 1.2. Is Python a Scripting Language?
      3. 1.3. Okay, But What's the Downside?
      4. 1.4. Who Uses Python Today?
      5. 1.5. What Can I Do with Python?
        1. 1.5.1. Systems Programming
        2. 1.5.2. GUIs
        3. 1.5.3. Internet Scripting
        4. 1.5.4. Component Integration
        5. 1.5.5. Database Programming
        6. 1.5.6. Rapid Prototyping
        7. 1.5.7. Numeric Programming
        8. 1.5.8. Gaming, Images, AI, XML, and More
      6. 1.6. What Are Python's Technical Strengths?
        1. 1.6.1. It's Object-Oriented
        2. 1.6.2. It's Free
        3. 1.6.3. It's Portable
        4. 1.6.4. It's Powerful
        5. 1.6.5. It's Mixable
        6. 1.6.6. It's Easy to Use
        7. 1.6.7. It's Easy to Learn
      7. 1.7. How Does Python Stack Up to Language X?
    2. 2. How Python Runs Programs
      1. 2.1. Introducing the Python Interpreter
      2. 2.2. Program Execution
        1. 2.2.1. The Programmer's View
        2. 2.2.2. Python's View
          1. 2.2.2.1. Byte code compilation
          2. 2.2.2.2. Python Virtual Machine (PVM)
          3. 2.2.2.3. Performance implications
          4. 2.2.2.4. Development implications
      3. 2.3. Execution Model Variations
        1. 2.3.1. Python Implementation Alternatives
          1. 2.3.1.1. CPython
          2. 2.3.1.2. Jython
          3. 2.3.1.3. Python.NET
        2. 2.3.2. The Psyco Just-in-Time Compiler
        3. 2.3.3. Frozen Binaries
        4. 2.3.4. Future Possibilities?
    3. 3. How You Run Programs
      1. 3.1. Interactive Coding
        1. 3.1.1. Using the Interactive Prompt
      2. 3.2. System Command Lines and Files
        1. 3.2.1. Using Command Lines and Files
        2. 3.2.2. Unix Executable Scripts (#!)
      3. 3.3. Clicking Windows File Icons
        1. 3.3.1. Clicking Icons on Windows
        2. 3.3.2. The raw_input Trick
        3. 3.3.3. Other Icon Click Limitations
      4. 3.4. Module Imports and Reloads
        1. 3.4.1. The Grander Module Story: Attributes
        2. 3.4.2. Import and Reload Usage Notes
      5. 3.5. The IDLE User Interface
        1. 3.5.1. IDLE Basics
        2. 3.5.2. Using IDLE
      6. 3.6. Other IDEs
      7. 3.7. Embedding Calls
      8. 3.8. Frozen Binary Executables
      9. 3.9. Text Editor Launch Options
      10. 3.10. Other Launch Options
      11. 3.11. Future Possibilities?
      12. 3.12. Which Option Should I Use?
      13. 3.13. Part I Exercises
  6. II. Types and Operations
    1. 4. Numbers
      1. 4.1. Python Program Structure
      2. 4.2. Why Use Built-in Types?
      3. 4.3. Numbers
        1. 4.3.1. Number Literals
        2. 4.3.2. Built-in Tools and Extensions
      4. 4.4. Python Expression Operators
        1. 4.4.1. Mixed Operators: Operator Precedence
        2. 4.4.2. Parentheses Group Subexpressions
        3. 4.4.3. Mixed Types: Converted Up
        4. 4.4.4. Preview: Operator Overloading
      5. 4.5. Numbers in Action
        1. 4.5.1. Basic Operations and Variables
        2. 4.5.2. Numeric Representation
        3. 4.5.3. Division: Classic, Floor, and True
        4. 4.5.4. B itwise Operations
        5. 4.5.5. L ong Integers
        6. 4.5.6. Complex Numbers
        7. 4.5.7. Hexadecimal and Octal Notation
        8. 4.5.8. Other Numeric Tools
      6. 4.6. The Dynamic Typing Interlude
        1. 4.6.1. How Assignments Work
        2. 4.6.2. References and Changeable Objects
        3. 4.6.3. References and Garbage Collection
    2. 5. Strings
      1. 5.1. String Literals
        1. 5.1.1. Single- and Double-Quoted Strings Are the Same
        2. 5.1.2. Escape Sequences Code Special Bytes
        3. 5.1.3. Raw Strings Suppress Escapes
        4. 5.1.4. Triple Quotes Code Multiline Block Strings
        5. 5.1.5. Unicode Strings Encode Larger Character Sets
      2. 5.2. Strings in Action
        1. 5.2.1. Basic Operations
        2. 5.2.2. Indexing and Slicing
          1. 5.2.2.1. I ndexing (S[i]) fetches components at offsets
          2. 5.2.2.2. S licing (S[i:j]) extracts contiguous sections of a sequence
        3. 5.2.3. String Conversion Tools
        4. 5.2.4. C hanging Strings
      3. 5.3. String Formatting
        1. 5.3.1. Advanced String Formatting
      4. 5.4. String Methods
        1. 5.4.1. String Method Examples: Changing Strings
        2. 5.4.2. String Method Examples: Parsing Text
        3. 5.4.3. The Original Module
      5. 5.5. General Type Categories
        1. 5.5.1. Types Share Operation Sets by Categories
        2. 5.5.2. Mutable Types Can Be Changed in-Place
    3. 6. Lists and Dictionaries
      1. 6.1. Lists
      2. 6.2. Lists in Action
        1. 6.2.1. Basic List Operations
        2. 6.2.2. In dexing, Slicing, and Matrixes
        3. 6.2.3. Changing Lists in-Place
          1. 6.2.3.1. Index and slice assignment
          2. 6.2.3.2. List method calls
      3. 6.3. Dictionaries
      4. 6.4. Dictionaries in Action
        1. 6.4.1. Basic Dictionary Operations
        2. 6.4.2. Changing Dictionaries in-Place
        3. 6.4.3. More Dictionary Methods
        4. 6.4.4. A Languages Table
        5. 6.4.5. Dictionary Usage Notes
          1. 6.4.5.1. Using dictionaries to simulate flexible lists
          2. 6.4.5.2. Using dictionaries for sparse data structures
          3. 6.4.5.3. Using dictionaries as "records"
    4. 7. Tuples, Files, and Everything Else
      1. 7.1. Tuples
        1. 7.1.1. Why Lists and Tuples?
      2. 7.2. Files
        1. 7.2.1. Files in Action
      3. 7.3. Type Categories Revisited
      4. 7.4. Object Generality
      5. 7.5. References Versus Copies
      6. 7.6. Comparisons, Equality, and Truth
      7. 7.7. Python's Type Hierarchies
      8. 7.8. Other Types in Python
      9. 7.9. Built-in Type Gotchas
        1. 7.9.1. Assignment Creates References, Not Copies
        2. 7.9.2. Repetition Adds One-Level Deep
          1. 7.9.2.1. Solutions
        3. 7.9.3. Cyclic Data Structures
        4. 7.9.4. Immutable Types Can't Be Changed in-Place
      10. 7.10. Part II Exercises
  7. III. Statements and Syntax
    1. 8. Assignment, Expressions, and Print
      1. 8.1. Assignment Statements
        1. 8.1.1. Variable Name Rules
          1. 8.1.1.1. Naming conventions
          2. 8.1.1.2. Names have no type, but objects do
        2. 8.1.2. Augmented Assignment Statements
      2. 8.2. Expression Statements
      3. 8.3. Print Statements
        1. 8.3.1. The Python "Hello World" Program
        2. 8.3.2. Redirecting the Output Stream
          1. 8.3.2.1. The print>>file extension
    2. 9. if Tests
      1. 9.1. if Statements
        1. 9.1.1. General Format
        2. 9.1.2. Examples
          1. 9.1.2.1. Multiway branching
      2. 9.2. Python Syntax Rules
        1. 9.2.1. Block Delimiters
        2. 9.2.2. Statement Delimiters
        3. 9.2.3. A Few Special Cases
      3. 9.3. Truth Tests
    3. 10. while and for Loops
      1. 10.1. while Loops
        1. 10.1.1. General Format
        2. 10.1.2. Examples
      2. 10.2. break, continue, pass, and the Loop else
        1. 10.2.1. General Loop Format
        2. 10.2.2. Examples
        3. 10.2.3. More on the Loop else
      3. 10.3. for Loops
        1. 10.3.1. General Format
        2. 10.3.2. Examples
      4. 10.4. Loop Variations
        1. 10.4.1. Counter Loops: range
        2. 10.4.2. Nonexhaustive Traversals: range
        3. 10.4.3. Changing Lists: range
        4. 10.4.4. Parallel Traversals: zip and map
        5. 10.4.5. Dictionary Construction with zip
    4. 11. Documenting Python Code
      1. 11.1. The Python Documentation Interlude
        1. 11.1.1. Documentation Sources
        2. 11.1.2. # Comments
        3. 11.1.3. The dir Function
        4. 11.1.4. Docstrings: __doc__
          1. 11.1.4.1. User-defined docstrings
          2. 11.1.4.2. Docstring standards
          3. 11.1.4.3. Built-in docstrings
        5. 11.1.5. PyDoc: The help Function
        6. 11.1.6. PyDoc: HTML Reports
        7. 11.1.7. Standard Manual Set
        8. 11.1.8. Web Resources
        9. 11.1.9. Published Books
      2. 11.2. Common Coding Gotchas
      3. 11.3. Part III Exercises
  8. IV. Functions
    1. 12. Function Basics
      1. 12.1. Why Use Functions?
      2. 12.2. Coding Functions
        1. 12.2.1. def Statements
        2. 12.2.2. def Executes at Runtime
      3. 12.3. A First Example: Definitions and Calls
        1. 12.3.1. Definition
        2. 12.3.2. Calls
        3. 12.3.3. Polymorphism in Python
      4. 12.4. A Second Example: Intersecting Sequences
        1. 12.4.1. Definition
        2. 12.4.2. Calls
        3. 12.4.3. Polymorphism Revisited
        4. 12.4.4. Local Variables
    2. 13. Scopes and Arguments
      1. 13.1. Scope Rules
        1. 13.1.1. Python Scope Basics
        2. 13.1.2. Name Resolution: The LEGB Rule
        3. 13.1.3. Scope Example
        4. 13.1.4. The Built-in Scope
      2. 13.2. The global Statement
      3. 13.3. Scopes and Nested Functions
        1. 13.3.1. Nested Scope Details
        2. 13.3.2. Nested Scope Examples
      4. 13.4. Passing Arguments
        1. 13.4.1. Arguments and Shared References
        2. 13.4.2. Avoiding Mutable Argument Changes
        3. 13.4.3. Simulating Output Parameters
      5. 13.5. Special Argument Matching Modes
        1. 13.5.1. Keyword and Default Examples
        2. 13.5.2. Arbitrary Arguments Examples
        3. 13.5.3. Combining Keywords and Defaults
        4. 13.5.4. The min Wakeup Call
          1. 13.5.4.1. Full credit
          2. 13.5.4.2. Bonus points
          3. 13.5.4.3. The punch line
        5. 13.5.5. A More Useful Example: General Set Functions
        6. 13.5.6. Argument Matching: The Gritty Details
    3. 14. Advanced Function Topics
      1. 14.1. Anonymous Functions: lambda
        1. 14.1.1. lambda Expressions
        2. 14.1.2. Why lambda?
        3. 14.1.3. How (Not) to Obfuscate Your Python Code
        4. 14.1.4. Nested lambdas and Scopes
      2. 14.2. Applying Functions to Arguments
        1. 14.2.1. The apply Built-in
          1. 14.2.1.1. Passing keyword arguments
        2. 14.2.2. Apply-Like Call Syntax
      3. 14.3. Mapping Functions Over Sequences
      4. 14.4. Functional Programming Tools
      5. 14.5. List Comprehensions
        1. 14.5.1. List Comprehension Basics
        2. 14.5.2. Adding Tests and Nested Loops
        3. 14.5.3. Comprehending List Comprehensions
      6. 14.6. Generators and Iterators
        1. 14.6.1. Generator Example
        2. 14.6.2. Iterators and Built-in Types
      7. 14.7. Function Design Concepts
        1. 14.7.1. Functions Are Objects: Indirect Calls
      8. 14.8. Function Gotchas
        1. 14.8.1. Local Names Are Detected Statically
        2. 14.8.2. Defaults and Mutable Objects
        3. 14.8.3. Functions Without Returns
      9. 14.9. Part IV Exercises
  9. V. Modules
    1. 15. Modules: The Big Picture
      1. 15.1. Why Use Modules?
      2. 15.2. Python Program Architecture
        1. 15.2.1. How to Structure a Program
        2. 15.2.2. Imports and Attributes
        3. 15.2.3. Standard Library Modules
      3. 15.3. How Imports Work
        1. 15.3.1. 1. Find It
          1. 15.3.1.1. The module search path
          2. 15.3.1.2. The sys.path list
          3. 15.3.1.3. Module file selection
        2. 15.3.2. 2. Compile It (Maybe)
        3. 15.3.3. 3. Run It
    2. 16. Module Coding Basics
      1. 16.1. Module Creation
      2. 16.2. Module Usage
        1. 16.2.1. The import Statement
        2. 16.2.2. The from statement
        3. 16.2.3. The from * statement
        4. 16.2.4. Imports Happen Only Once
        5. 16.2.5. import and from Are Assignments
        6. 16.2.6. Cross-File Name Changes
        7. 16.2.7. import and from Equivalence
      3. 16.3. Module Namespaces
        1. 16.3.1. Files Generate Namespaces
        2. 16.3.2. Attribute Name Qualification
        3. 16.3.3. Imports Versus Scopes
        4. 16.3.4. Namespace Nesting
      4. 16.4. Reloading Modules
        1. 16.4.1. Reload Basics
        2. 16.4.2. Reload Example
    3. 17. Module Packages
      1. 17.1. Package Import Basics
        1. 17.1.1. Packages and Search Path Settings
        2. 17.1.2. Package __init__.py Files
      2. 17.2. Package Import Example
        1. 17.2.1. from Versus import with Packages
      3. 17.3. Why Use Package Imports?
      4. 17.4. A Tale of Three Systems
    4. 18. Advanced Module Topics
      1. 18.1. Data Hiding in Modules
        1. 18.1.1. Minimizing from* damage: _X and __all__
      2. 18.2. Enabling Future Language Features
      3. 18.3. Mixed Usage Modes: __name__ and __main__
      4. 18.4. Changing the Module Search Path
      5. 18.5. The import as Extension
      6. 18.6. Module Design Concepts
        1. 18.6.1. Modules Are Objects: Metaprograms
      7. 18.7. Module Gotchas
        1. 18.7.1. Importing Modules by Name String
        2. 18.7.2. from Copies Names but Doesn't Link
        3. 18.7.3. Statement Order Matters in Top-Level Code
        4. 18.7.4. Recursive "from" Imports May Not Work
        5. 18.7.5. reload May Not Impact from Imports
        6. 18.7.6. reload and from and Interactive Testing
        7. 18.7.7. reload Isn't Applied Transitively
      8. 18.8. Part V Exercises
  10. VI. Classes and OOP
    1. 19. OOP: The Big Picture
      1. 19.1. Why Use Classes?
      2. 19.2. OOP from 30,000 Feet
        1. 19.2.1. Attribute Inheritance Search
        2. 19.2.2. Coding Class Trees
        3. 19.2.3. OOP Is About Code Reuse
    2. 20. Class Coding Basics
      1. 20.1. Classes Generate Multiple Instance Objects
        1. 20.1.1. Class Objects Provide Default Behavior
        2. 20.1.2. Instance Objects Are Concrete Items
        3. 20.1.3. A First Example
      2. 20.2. Classes Are Customized by Inheritance
        1. 20.2.1. A Second Example
        2. 20.2.2. Classes and Modules
      3. 20.3. Classes Can Intercept Python Operators
        1. 20.3.1. A Third Example
        2. 20.3.2. Why Operator Overloading?
    3. 21. Class Coding Details
      1. 21.1. The Class Statement
        1. 21.1.1. General Form
        2. 21.1.2. Example
      2. 21.2. Methods
        1. 21.2.1. Example
        2. 21.2.2. Calling Superclass Constructors
        3. 21.2.3. Other Method Call Possibilities
      3. 21.3. Inheritance
        1. 21.3.1. Attribute Tree Construction
        2. 21.3.2. Specializing Inherited Methods
        3. 21.3.3. Class Interface Techniques
        4. 21.3.4. Abstract Superclasses
      4. 21.4. Operator Overloading
        1. 21.4.1. Common Operator Overloading Methods
        2. 21.4.2. __getitem__ Intercepts Index References
        3. 21.4.3. __getitem__ and __iter__ Implement Iteration
          1. 21.4.3.1. User-defined iterators
        4. 21.4.4. __getattr__ and __setattr__ Catch Attribute References
        5. 21.4.5. __repr__ and __str__Return String Representations
        6. 21.4.6. __radd__ Handles Right-Side Addition
        7. 21.4.7. __call__ Intercepts Calls
        8. 21.4.8. __del__ Is a Destructor
      5. 21.5. Namespaces: The Whole Story
        1. 21.5.1. Unqualified Names: Global Unless Assigned
        2. 21.5.2. Qualified Names: Object Namespaces
        3. 21.5.3. Assignments Classify Names
        4. 21.5.4. Namespace Dictionaries
        5. 21.5.5. Namespace Links
    4. 22. Designing with Classes
      1. 22.1. Python and OOP
        1. 22.1.1. Overloading by Call Signatures (or Not)
      2. 22.2. Classes as Records
      3. 22.3. OOP and Inheritance: "is-a" Relationships
      4. 22.4. OOP and Composition: "has-a" Relationships
        1. 22.4.1. Stream Processors Revisited
      5. 22.5. OOP and Delegation
      6. 22.6. Multiple Inheritance
      7. 22.7. Classes Are Objects: Generic Object Factories
        1. 22.7.1. Why Factories?
      8. 22.8. Methods Are Objects: Bound or Unbound
      9. 22.9. Documentation Strings Revisited
      10. 22.10. Classes Versus Modules
    5. 23. Advanced Class Topics
      1. 23.1. Extending Built-in Types
        1. 23.1.1. Extending Types by Embedding
        2. 23.1.2. Extending Types by Subclassing
      2. 23.2. Pseudo-Private Class Attributes
        1. 23.2.1. Name Mangling Overview
        2. 23.2.2. Why Use Pseudo-Private Attributes?
      3. 23.3. "New Style" Classes in Python 2.2
        1. 23.3.1. Diamond Inheritance Change
          1. 23.3.1.1. Diamond inheritance example
          2. 23.3.1.2. Explicit conflict resolution
        2. 23.3.2. Other New Style Class Extensions
          1. 23.3.2.1. Static and class methods
          2. 23.3.2.2. Instance slots
          3. 23.3.2.3. Class properties
          4. 23.3.2.4. New __getattribute__ overload method
      4. 23.4. Class Gotchas
        1. 23.4.1. Changing Class Attributes Can Have Side Effects
        2. 23.4.2. Multiple Inheritance: Order Matters
        3. 23.4.3. Class Function Attributes Are Special: Static Methods
          1. 23.4.3.1. Solution (prior to 2.2, and in 2.2 normally)
          2. 23.4.3.2. Static and class methods in Python 2.2
        4. 23.4.4. Methods, Classes, and Nested Scopes
        5. 23.4.5. Overwrapping-itis
      5. 23.5. Part VI Exercises
  11. VII. Exceptions and Tools
    1. 24. Exception Basics
      1. 24.1. Why Use Exceptions?
        1. 24.1.1. Exception Roles
      2. 24.2. Exception Handling: The Short Story
      3. 24.3. The try/except/else Statement
        1. 24.3.1. Try Statement Clauses
        2. 24.3.2. The try/else Clause
        3. 24.3.3. Example: Default Behavior
        4. 24.3.4. Example: Catching Built-in Exceptions
      4. 24.4. The try/finally Statement
        1. 24.4.1. Example: Coding Termination Actions with try/finally
      5. 24.5. The raise Statement
        1. 24.5.1. Example: Raising and Catching User-Defined Exceptions
        2. 24.5.2. Example: Passing Extra Data with raise
        3. 24.5.3. Example: Propagating Exceptions with raise
      6. 24.6. The assert Statement
        1. 24.6.1. Example: Trapping Constraints (but Not Errors)
    2. 25. Exception Objects
      1. 25.1. String-Based Exceptions
      2. 25.2. Class-Based Exceptions
        1. 25.2.1. Class Exception Example
        2. 25.2.2. Why Class Exceptions?
        3. 25.2.3. Built-in Exception Classes
        4. 25.2.4. Specifying Exception Text
        5. 25.2.5. Sending Extra Data in Instances
          1. 25.2.5.1. Example: extra data with classes and strings
      3. 25.3. General raise Statement Forms
    3. 26. Designing with Exceptions
      1. 26.1. Nesting Exception Handlers
        1. 26.1.1. Example: Control-Flow Nesting
        2. 26.1.2. Example: Syntactic Nesting
      2. 26.2. Exception Idioms
        1. 26.2.1. Exceptions Aren't Always Errors
        2. 26.2.2. Functions Signal Conditions with raise
        3. 26.2.3. Debugging with Outer try Statements
        4. 26.2.4. Running in-Process Tests
      3. 26.3. Exception Design Tips
        1. 26.3.1. What Should Be Wrapped
        2. 26.3.2. Catching Too Much
        3. 26.3.3. Catching Too Little
      4. 26.4. Exception Gotchas
        1. 26.4.1. String Exceptions Match by Identity, Not Value
        2. 26.4.2. Catching the Wrong Thing
      5. 26.5. Core Language Summary
        1. 26.5.1. The Python Toolset
        2. 26.5.2. Development Tools for Larger Projects
      6. 26.6. Part VII Exercises
  12. VIII. The Outer Layers
    1. 27. Common Tasks in Python
      1. 27.1. Exploring on Your Own
      2. 27.2. Conversions, Numbers, and Comparisons
      3. 27.3. Manipulating Strings
        1. 27.3.1. The string Module
        2. 27.3.2. Complicated String Matches with Regular Expressions
          1. 27.3.2.1. A real regular expression problem
      4. 27.4. Data Structure Manipulations
        1. 27.4.1. Making Copies
          1. 27.4.1.1. The copy module
        2. 27.4.2. Sorting
        3. 27.4.3. Randomizing
        4. 27.4.4. Making New Data Structures
        5. 27.4.5. Making New Lists and Dictionaries
      5. 27.5. Manipulating Files and Directories
        1. 27.5.1. The os and os.path Modules
        2. 27.5.2. Copying Files and Directories: The shutil Module
        3. 27.5.3. Filenames and Directories
        4. 27.5.4. Matching Sets of Files
        5. 27.5.5. Using Temporary Files
        6. 27.5.6. Modifying Input and Outputs
        7. 27.5.7. Using Standard I/O to Process Files
          1. 27.5.7.1. Finding all lines that start with a #
          2. 27.5.7.2. Extracting the fourth column of a file (where columns are defined by whitespace)
          3. 27.5.7.3. Extracting the fourth column of a file, where columns are separated by colons, and making it lowercase
          4. 27.5.7.4. Printing the first 10 lines, the last 10 lines, and every other line
          5. 27.5.7.5. Counting the number of times the word "Python" occurs in a file
          6. 27.5.7.6. Changing a list of columns into a list of rows
          7. 27.5.7.7. Choosing chunk sizes
        8. 27.5.8. Doing Something to a Set of Files Specified on the Command Line
        9. 27.5.9. Processing Each Line of One or More Files
        10. 27.5.10. Dealing with Binary Data: The struct Module
      6. 27.6. Internet-Related Modules
        1. 27.6.1. The Common Gateway Interface: The cgi Module
        2. 27.6.2. Manipulating URLs: The urllib and urlparse Modules
        3. 27.6.3. Specific Internet Protocols
        4. 27.6.4. Processing Internet Data
        5. 27.6.5. XML Processing
      7. 27.7. Executing Programs
      8. 27.8. Debugging, Testing, Timing, Profiling
        1. 27.8.1. Debugging with pdb
        2. 27.8.2. Testing with unittest
        3. 27.8.3. Timing
      9. 27.9. Exercises
    2. 28. Frameworks
      1. 28.1. An Automated Complaint System
        1. 28.1.1. Excerpt from the HTML File
      2. 28.2. Interfacing with COM: Cheap Public Relations
      3. 28.3. A Tkinter-Based GUI Editor for Managing Form Data
        1. 28.3.1. The Main Program
        2. 28.3.2. The Form Editor
        3. 28.3.3. Design Considerations
      4. 28.4. Jython: The Felicitous Union of Python and Java
        1. 28.4.1. Jython Gives Python Programmers Access to Java Libraries
        2. 28.4.2. Jython as a Java Scripting Language
        3. 28.4.3. A Real Jython/Swing Application: grapher.py
      5. 28.5. Exercises
    3. 29. Python Resources
      1. 29.1. Layers of Community
        1. 29.1.1. The Core
        2. 29.1.2. Local User Groups
        3. 29.1.3. Conferences and Workshops
        4. 29.1.4. Where to Get Help
          1. 29.1.4.1. Python-help
          2. 29.1.4.2. Python-tutor
          3. 29.1.4.3. Python-list
        5. 29.1.5. Special Interest Groups
        6. 29.1.6. python-dev
        7. 29.1.7. News Sources
      2. 29.2. The Process
      3. 29.3. Services and Products
      4. 29.4. The Legal Framework: The Python Software Foundation
      5. 29.5. Software
        1. 29.5.1. Search the Web
        2. 29.5.2. Search the Mailing List Archives
        3. 29.5.3. Look in the Vaults of Parnassus
        4. 29.5.4. Check the Python Package Index (PyPI)
        5. 29.5.5. Look in the Python Cookbook
      6. 29.6. Popular Third-Party Software
        1. 29.6.1. Interfaces to Windows and the MacOS
          1. 29.6.1.1. Windows
          2. 29.6.1.2. Macintosh
        2. 29.6.2. Special-Purpose Libraries
          1. 29.6.2.1. Scientific computing libraries
          2. 29.6.2.2. Relational database interfaces
          3. 29.6.2.3. Graphics libraries
            1. 29.6.2.3.1. Python Imaging Library (PIL)
            2. 29.6.2.3.2. PyGame and PyOpenGL
        3. 29.6.3. Interfaces to GUI Toolkits
        4. 29.6.4. Interfaces to C/C++/Fortran
          1. 29.6.4.1. SWIG and f2py
          2. 29.6.4.2. CXX and Boost::Python
          3. 29.6.4.3. Pyrex, Weave, and Psyco
          4. 29.6.4.4. ctypes
        5. 29.6.5. Little Gems
        6. 29.6.6. Packaging Tools
          1. 29.6.6.1. Installer
          2. 29.6.6.2. py2exe
      7. 29.7. Web Application Frameworks
        1. 29.7.1. Zope
        2. 29.7.2. Twisted
        3. 29.7.3. Quixote
        4. 29.7.4. Webware, Spyce, and More
      8. 29.8. Tools for Python Developers
  13. IX. Appendixes
    1. A. Installation and Configuration
      1. A.1. Installing the Python Interpreter
        1. A.1.1. Where to Get Python
        2. A.1.2. Installation Steps
        3. A.1.3. Configuration Steps
          1. A.1.3.1. Python environment variables
        4. A.1.4. How to Set Configuration Options
          1. A.1.4.1. UNIX/Linux shell variables
          2. A.1.4.2. DOS variables (Windows)
          3. A.1.4.3. Other Windows options
          4. A.1.4.4. Path files
    2. B. Solutions to Exercises
      1. B.1. Part I
      2. B.2. Part II
      3. B.3. Part III
      4. B.4. Part IV
      5. B.5. Part V
      6. B.6. Part VI
      7. B.7. Part VII
      8. B.8. Part VIII
        1. B.8.1. Chapter 27
        2. B.8.2. Chapter 28
  14. About the Authors
  15. Colophon
  16. Copyright