Programming Python, 3rd Edition

Book description

Already the industry standard for Python users, ProgrammingPython fromO'Reilly just got even better. This third edition has been updated toreflect current best practices andthe abundance of changes introduced by the latest version of thelanguage, Python 2.5.

Whether you're a novice or an advancedpractitioner, you'll find thisrefreshed book more than lives up to its reputation. ProgrammingPython, 3rd Edition, teaches you the rightway to code. It explains Python language syntax and programmingtechniques in a clear and concisemanner, with numerous examples that illustrate both correct usage andcommon idioms. By reading thiscomprehensive guide, you'll learn how to apply Python in real-worldproblem domains such as:

  • GUI programming
  • Internet scripting
  • Parallel processing
  • Database management
  • Networked applications

Programming Python, Third Edition coverseach of thesetarget domainsgradually, beginning with in-depth discussions of core concepts andthen progressing toward completeprograms. Large examples do appear, but only after you've learnedenough to understand their techniques andcode.

Along the way, you'll also learn how to use the Python language inrealistically scaled programs--concepts such as Object-Oriented Programming (OOP) and code reuseare recurring side themes throughout thistext. If you're interested in Python programming, then this O'Reillyclassic needs to be within arm's reach. Thewealth of practical advice, snippets of code, and patterns of programdesign can all be put into use on adaily basis--making your life easier and more productive.

Reviews of the second edition:

"...about as comprehensive as any book can be."
--Dr. Dobb's Journal

"If the language had manuals, they would undoubtedlybe the texts from O'Reilly...'Learning Python' and 'Programming Python'are definitive treatments."
--SD Times

Publisher resources

View/Submit Errata

Table of contents

  1. Programming Python, 3rd Edition
  2. A Note Regarding Supplemental Files
  3. Foreword
    1. How Time Flies!
    2. Coming Attractions
    3. Concluding Remarks
    4. Foreword to the Second Edition (2001)
    5. Foreword from the First Edition (1996)
  4. Preface
    1. “And Now for Something Completely Different . . . Again”
    2. About This Book
    3. About This Edition
      1. Python Changes
      2. Example Changes
      3. Topic Changes
      4. Focus Unchanged
    4. This Book’s Motivation
    5. This Book’s Structure
    6. This Edition’s Design
      1. It’s Been Updated for Python 2.4 (and 2.5)
      2. It’s Been Reorganized
      3. It Covers New Topics
      4. It’s Still Mostly Platform-Neutral
        1. C integration code platform issues
      5. It’s Still Focused for a More Advanced Audience
      6. It’s Still Example-Oriented
    7. Using the Book’s Examples
      1. The Book Examples Tree
      2. The Book Examples Distribution Package
      3. Running Examples: The Short Story
      4. Running Examples: The Details
        1. Demos and gadgets
        2. Setup requirements
        3. Web-based examples
        4. Top-level programs
    8. Conventions Used in This Book
    9. Safari® Enabled
    10. Where to Look for Updates
    11. Contacting O’Reilly
    12. Using Code Examples
    13. Acknowledgments
  5. I. The Beginning
    1. 1. Introducing Python
      1. 1.1. “And Now for Something Completely Different”
      2. 1.2. Python Philosophy 101
      3. 1.3. The Life of Python
      4. 1.4. Signs of the Python Times
        1. 1.4.1. Recent Growth (As of 2005, at Least)
      5. 1.5. The Compulsory Features List
      6. 1.6. What’s Python Good For?
      7. 1.7. What’s Python Not Good For?
      8. 1.8. Truth in Advertising
    2. 2. A Sneak Preview
      1. 2.1. “Programming Python: The Short Story”
      2. 2.2. The Task
      3. 2.3. Step 1: Representing Records
        1. 2.3.1. Using Lists
          1. 2.3.1.1. A database list
          2. 2.3.1.2. Field labels
        2. 2.3.2. Using Dictionaries
          1. 2.3.2.1. Other ways to make dictionaries
          2. 2.3.2.2. Lists of dictionaries
          3. 2.3.2.3. Nested structures
          4. 2.3.2.4. Dictionaries of dictionaries
      4. 2.4. Step 2: Storing Records Persistently
        1. 2.4.1. Using Formatted Files
          1. 2.4.1.1. Test data script
          2. 2.4.1.2. Data format script
          3. 2.4.1.3. Utility scripts
        2. 2.4.2. Using Pickle Files
        3. 2.4.3. Using Per-Record Pickle Files
        4. 2.4.4. Using Shelves
      5. 2.5. Step 3: Stepping Up to OOP
        1. 2.5.1. Using Classes
        2. 2.5.2. Adding Behavior
        3. 2.5.3. Adding Inheritance
        4. 2.5.4. Refactoring Code
          1. 2.5.4.1. Augmenting methods
          2. 2.5.4.2. Display format
          3. 2.5.4.3. Constructor customization
          4. 2.5.4.4. Alternative classes
        5. 2.5.5. Adding Persistence
        6. 2.5.6. Other Database Options
      6. 2.6. Step 4: Adding Console Interaction
        1. 2.6.1. A Console Shelve Interface
      7. 2.7. Step 5: Adding a GUI
        1. 2.7.1. GUI Basics
        2. 2.7.2. Using OOP for GUIs
        3. 2.7.3. Getting Input from a User
        4. 2.7.4. A GUI Shelve Interface
          1. 2.7.4.1. Coding the GUI
          2. 2.7.4.2. Using the GUI
          3. 2.7.4.3. Future directions
      8. 2.8. Step 6: Adding a Web Interface
        1. 2.8.1. CGI Basics
        2. 2.8.2. Running a Web Server
        3. 2.8.3. Using Query Strings and urllib
        4. 2.8.4. Formatting Reply Text
        5. 2.8.5. A Web-Based Shelve Interface
          1. 2.8.5.1. Coding the web site
          2. 2.8.5.2. Using the web site
          3. 2.8.5.3. Future directions
      9. 2.9. The End of the Demo
  6. II. System Programming
    1. 3. System Tools
      1. 3.1. “The os.path to Knowledge”
        1. 3.1.1. Why Python Here?
        2. 3.1.2. The Next Five Chapters
      2. 3.2. System Scripting Overview
        1. 3.2.1. Python System Modules
        2. 3.2.2. Module Documentation Sources
        3. 3.2.3. Paging Documentation Strings
        4. 3.2.4. Introducing String Methods
        5. 3.2.5. File Operation Basics
        6. 3.2.6. Using Programs in Two Ways
        7. 3.2.7. Python Library Manuals
        8. 3.2.8. Commercially Published References
      3. 3.3. Introducing the sys Module
        1. 3.3.1. Platforms and Versions
        2. 3.3.2. The Module Search Path
        3. 3.3.3. The Loaded Modules Table
        4. 3.3.4. Exception Details
        5. 3.3.5. Other sys Module Exports
      4. 3.4. Introducing the os Module
        1. 3.4.1. The Big os Lists
        2. 3.4.2. Administrative Tools
        3. 3.4.3. Portability Constants
        4. 3.4.4. Basic os.path Tools
        5. 3.4.5. Running Shell Commands from Scripts
          1. 3.4.5.1. What’s a shell command?
          2. 3.4.5.2. Running shell commands
          3. 3.4.5.3. Communicating with shell commands
          4. 3.4.5.4. Shell command limitations
        6. 3.4.6. Other os Module Exports
      5. 3.5. Script Execution Context
      6. 3.6. Current Working Directory
        1. 3.6.1. CWD, Files, and Import Paths
        2. 3.6.2. CWD and Command Lines
      7. 3.7. Command-Line Arguments
      8. 3.8. Shell Environment Variables
        1. 3.8.1. Fetching Shell Variables
        2. 3.8.2. Changing Shell Variables
        3. 3.8.3. Shell Variable Details
      9. 3.9. Standard Streams
        1. 3.9.1. Redirecting Streams to Files and Programs
          1. 3.9.1.1. Redirecting streams to files
          2. 3.9.1.2. Chaining programs with pipes
          3. 3.9.1.3. Coding alternatives
          4. 3.9.1.4. Redirected streams and user interaction
          5. 3.9.1.5. Reading keyboard input
        2. 3.9.2. Redirecting Streams to Python Objects
        3. 3.9.3. The StringIO Module
        4. 3.9.4. Capturing the stderr Stream
        5. 3.9.5. Redirection Syntax in Print Statements
        6. 3.9.6. Other Redirection Options
    2. 4. File and Directory Tools
      1. 4.1. “Erase Your Hard Drive in Five Easy Steps!”
      2. 4.2. File Tools
        1. 4.2.1. Built-In File Objects
          1. 4.2.1.1. Output files
            1. 4.2.1.1.1. Opening
            2. 4.2.1.1.2. Writing
            3. 4.2.1.1.3. Closing
          2. 4.2.1.2. Input files
          3. 4.2.1.3. Reading lines with file iterators
          4. 4.2.1.4. Other file object modes
          5. 4.2.1.5. Binary datafiles
          6. 4.2.1.6. End-of-line translations on Windows
          7. 4.2.1.7. Parsing packed binary data with the struct module
        2. 4.2.2. File Tools in the os Module
          1. 4.2.2.1. Open mode flags
          2. 4.2.2.2. Other os file tools
        3. 4.2.3. File Scanners
      3. 4.3. Directory Tools
        1. 4.3.1. Walking One Directory
          1. 4.3.1.1. Running shell listing commands with os.popen
          2. 4.3.1.2. The glob module
          3. 4.3.1.3. The os.listdir call
          4. 4.3.1.4. Splitting and joining listing results
        2. 4.3.2. Walking Directory Trees
          1. 4.3.2.1. The os.path.walk visitor
          2. 4.3.2.2. The os.walk generator
          3. 4.3.2.3. Recursive os.listdir traversals
        3. 4.3.3. Rolling Your Own find Module
    3. 5. Parallel System Tools
      1. 5.1. “Telling the Monkeys What to Do”
      2. 5.2. Forking Processes
        1. 5.2.1. The fork/exec Combination
          1. 5.2.1.1. os.exec call formats
          2. 5.2.1.2. Spawned child program
      3. 5.3. Threads
        1. 5.3.1. The thread Module
          1. 5.3.1.1. Synchronizing access to global objects
          2. 5.3.1.2. Waiting for spawned thread exits
        2. 5.3.2. The threading Module
        3. 5.3.3. The Queue Module
        4. 5.3.4. The Global Interpreter Lock and Threads
          1. 5.3.4.1. The thread switch interval
          2. 5.3.4.2. Atomic operations
          3. 5.3.4.3. C API thread considerations
      4. 5.4. Program Exits
        1. 5.4.1. os Module Exits
        2. 5.4.2. Exit Status Codes
        3. 5.4.3. Process Exit Status
        4. 5.4.4. Thread Exits
      5. 5.5. Interprocess Communication
      6. 5.6. Pipes
        1. 5.6.1. Anonymous Pipe Basics
        2. 5.6.2. Bidirectional IPC with Pipes
          1. 5.6.2.1. Deadlocks, flushes, and unbuffered streams
        3. 5.6.3. Named Pipes (Fifos)
      7. 5.7. Signals
      8. 5.8. Other Ways to Start Programs
        1. 5.8.1. The os.spawn Calls
        2. 5.8.2. Launching Programs on Windows
          1. 5.8.2.1. Using the DOS start command
          2. 5.8.2.2. Using start in Python scripts
          3. 5.8.2.3. The os.startfile call
        3. 5.8.3. Other Program Launch Options
      9. 5.9. A Portable Program-Launch Framework
      10. 5.10. Other System Tools
    4. 6. System Examples: Utilities
      1. 6.1. “Splits and Joins and Alien Invasions”
      2. 6.2. Splitting and Joining Files
        1. 6.2.1. Splitting Files Portably
          1. 6.2.1.1. Operation modes
          2. 6.2.1.2. Binary file access
          3. 6.2.1.3. Manually closing files
        2. 6.2.2. Joining Files Portably
          1. 6.2.2.1. Reading by blocks or files
          2. 6.2.2.2. Sorting filenames
        3. 6.2.3. Usage Variations
      3. 6.3. Generating Forward-Link Web Pages
        1. 6.3.1. Page Template File
        2. 6.3.2. Page Generator Script
      4. 6.4. A Regression Test Script
      5. 6.5. Packing and Unpacking Files
        1. 6.5.1. Packing Files “++”
        2. 6.5.2. Application Hierarchy Superclasses
          1. 6.5.2.1. StreamApp: adding stream redirection
          2. 6.5.2.2. App: the root class
          3. 6.5.2.3. Why use classes here?
      6. 6.6. Automated Program Launchers
        1. 6.6.1. Launcher Module Clients
        2. 6.6.2. Launching Programs Without Environment Settings
        3. 6.6.3. Launching Web Browsers Portably
          1. 6.6.3.1. Launching browsers with command lines
          2. 6.6.3.2. Launching browsers with function calls
          3. 6.6.3.3. Viewing multimedia in browsers
        4. 6.6.4. A Portable Media File Player Tool
          1. 6.6.4.1. The Python webbrowser module
          2. 6.6.4.2. The Python mimetypes module
    5. 7. System Examples: Directories
      1. 7.1. “The Greps of Wrath”
      2. 7.2. Fixing DOS Line Ends
        1. 7.2.1. Converting Line Ends in One File
          1. 7.2.1.1. Slinging bytes and verifying results
          2. 7.2.1.2. Nonintrusive conversions
          3. 7.2.1.3. Slicing strings out of bounds
          4. 7.2.1.4. Binary file mode revisited
        2. 7.2.2. Converting Line Ends in One Directory
        3. 7.2.3. Converting Line Ends in an Entire Tree
          1. 7.2.3.1. The view from the top
      3. 7.3. Fixing DOS Filenames
        1. 7.3.1. Rewriting with os.path.walk
      4. 7.4. Searching Directory Trees
        1. 7.4.1. Greps and Globs in Shells and Python
          1. 7.4.1.1. Cleaning up bytecode files
        2. 7.4.2. A Python Tree Searcher
      5. 7.5. Visitor: Walking Trees Generically
        1. 7.5.1. Editing Files in Directory Trees
        2. 7.5.2. Global Replacements in Directory Trees
        3. 7.5.3. Collecting Matched Files in Trees
          1. 7.5.3.1. Suppressing status messages
        4. 7.5.4. Recoding Fixers with Visitors
        5. 7.5.5. Fixing File Permissions in Trees
        6. 7.5.6. Changing Unix Executable Path Lines
        7. 7.5.7. Summary: Counting Source Lines Four Ways
      6. 7.6. Copying Directory Trees
        1. 7.6.1. A Python Tree Copy Script
        2. 7.6.2. Recoding Copies with a Visitor-Based Class
      7. 7.7. Deleting Directory Trees
        1. 7.7.1. Recoding Deletions for Generality
      8. 7.8. Comparing Directory Trees
        1. 7.8.1. Finding Directory Differences
        2. 7.8.2. Finding Tree Differences
        3. 7.8.3. Running the Script
          1. 7.8.3.1. Verifying CD backups
        4. 7.8.4. Reporting Differences
  7. III. GUI Programming
    1. 8. Graphical User Interfaces
      1. 8.1. “Here’s Looking at You, Kid”
        1. 8.1.1. GUI Programming Topics
      2. 8.2. Python GUI Development Options
      3. 8.3. Tkinter Overview
        1. 8.3.1. Tkinter Pragmatics
        2. 8.3.2. Tkinter Documentation
        3. 8.3.3. Tkinter Extensions
        4. 8.3.4. Tkinter Structure
      4. 8.4. Climbing the GUI Learning Curve
        1. 8.4.1. “Hello World” in Four Lines (or Less)
      5. 8.5. Tkinter Coding Basics
        1. 8.5.1. Making Widgets
        2. 8.5.2. Geometry Managers
        3. 8.5.3. Running GUI Programs
          1. 8.5.3.1. Avoiding DOS consoles on Windows
      6. 8.6. Tkinter Coding Alternatives
        1. 8.6.1. Widget Resizing Basics
        2. 8.6.2. Configuring Widget Options and Window Titles
        3. 8.6.3. One More for Old Times’ Sake
        4. 8.6.4. Packing Widgets Without Saving Them
      7. 8.7. Adding Buttons and Callbacks
        1. 8.7.1. Widget Resizing Revisited: Expansion
      8. 8.8. Adding User-Defined Callback Handlers
        1. 8.8.1. Lambda Callback Handlers
          1. 8.8.1.1. Passing in values with default arguments
          2. 8.8.1.2. Passing in values with enclosing scope references
          3. 8.8.1.3. Enclosing scopes versus defaults
        2. 8.8.2. Bound Method Callback Handlers
        3. 8.8.3. Callable Class Object Callback Handlers
        4. 8.8.4. Other Tkinter Callback Protocols
        5. 8.8.5. Binding Events
      9. 8.9. Adding Multiple Widgets
        1. 8.9.1. Widget Resizing Revisited: Clipping
        2. 8.9.2. Attaching Widgets to Frames
        3. 8.9.3. Layout: Packing Order and Side Attachments
        4. 8.9.4. The Packer’s Expand and Fill Revisited
        5. 8.9.5. Using Anchor to Position Instead of Stretch
      10. 8.10. Customizing Widgets with Classes
      11. 8.11. Reusable GUI Components with Classes
        1. 8.11.1. Attaching Class Components
        2. 8.11.2. Extending Class Components
        3. 8.11.3. Standalone Container Classes
      12. 8.12. The End of the Tutorial
      13. 8.13. Python/Tkinter for Tcl/Tk Converts
    2. 9. A Tkinter Tour, Part 1
      1. 9.1. “Widgets and Gadgets and GUIs, Oh My!”
        1. 9.1.1. This Chapter’s Topics
      2. 9.2. Configuring Widget Appearance
      3. 9.3. Top-Level Windows
        1. 9.3.1. Toplevel and Tk Widgets
        2. 9.3.2. Top-Level Window Protocols
      4. 9.4. Dialogs
        1. 9.4.1. Standard (Common) Dialogs
          1. 9.4.1.1. A “smart” and reusable Quit button
          2. 9.4.1.2. A dialog demo launcher bar
          3. 9.4.1.3. Printing dialog results (and passing callback data with lambdas)
          4. 9.4.1.4. Letting users select colors on the fly
          5. 9.4.1.5. Other standard dialog calls
        2. 9.4.2. The Old-Style Dialog Module
        3. 9.4.3. Custom Dialogs
          1. 9.4.3.1. Making custom dialogs modal
          2. 9.4.3.2. Other ways to be modal
      5. 9.5. Binding Events
      6. 9.6. Message and Entry
        1. 9.6.1. Message
        2. 9.6.2. Entry
          1. 9.6.2.1. Programming Entry widgets
          2. 9.6.2.2. Laying out input forms
          3. 9.6.2.3. Going modal again
          4. 9.6.2.4. Tkinter “variables”
      7. 9.7. Checkbutton, Radiobutton, and Scale
        1. 9.7.1. Checkbuttons
          1. 9.7.1.1. Check buttons and variables
        2. 9.7.2. Radio Buttons
          1. 9.7.2.1. Radio buttons and variables
          2. 9.7.2.2. Radio buttons without variables
          3. 9.7.2.3. Hold onto your variables
        3. 9.7.3. Scales (Sliders)
          1. 9.7.3.1. Scales and variables
      8. 9.8. Running GUI Code Three Ways
        1. 9.8.1. Attaching Frames
        2. 9.8.2. Independent Windows
        3. 9.8.3. Running Programs
          1. 9.8.3.1. Cross-program communication
          2. 9.8.3.2. Coding for reusability
      9. 9.9. Images
        1. 9.9.1. Fun with Buttons and Pictures
      10. 9.10. Viewing and Processing Images with PIL
        1. 9.10.1. PIL Basics
        2. 9.10.2. Displaying Other Image Types with PIL
          1. 9.10.2.1. Displaying all images in a directory
        3. 9.10.3. Creating Image Thumbnails with PIL
          1. 9.10.3.1. Performance: saving thumbnail files
          2. 9.10.3.2. Layout: gridding and fixed-size widgets
          3. 9.10.3.3. Scrolling and canvases
    3. 10. A Tkinter Tour, Part 2
      1. 10.1. “On Today’s Menu: Spam, Spam, and Spam”
      2. 10.2. Menus
        1. 10.2.1. Top-Level Window Menus
        2. 10.2.2. Frame- and Menubutton-Based Menus
          1. 10.2.2.1. Using Menubuttons and Optionmenus
        3. 10.2.3. Windows with Both Menus and Toolbars
          1. 10.2.3.1. Automating menu construction
      3. 10.3. Listboxes and Scrollbars
        1. 10.3.1. Programming Listboxes
        2. 10.3.2. Programming Scroll Bars
        3. 10.3.3. Packing Scroll Bars
      4. 10.4. Text
        1. 10.4.1. Programming the Text Widget
          1. 10.4.1.1. Text is a Python string
          2. 10.4.1.2. String positions
            1. 10.4.1.2.1. Text indexes
            2. 10.4.1.2.2. Text marks
            3. 10.4.1.2.3. Text tags
        2. 10.4.2. Adding Text-Editing Operations
          1. 10.4.2.1. Using the clipboard
          2. 10.4.2.2. Composition versus inheritance
          3. 10.4.2.3. It’s called “Simple” for a reason
        3. 10.4.3. Advanced Text and Tag Operations
      5. 10.5. Canvas
        1. 10.5.1. Basic Canvas Operations
        2. 10.5.2. Programming the Canvas Widget
          1. 10.5.2.1. Coordinates
          2. 10.5.2.2. Object construction
          3. 10.5.2.3. Object identifiers and operations
          4. 10.5.2.4. Canvas object tags
        3. 10.5.3. Scrolling Canvases
        4. 10.5.4. Scrollable Canvases and Image Thumbnails
          1. 10.5.4.1. Scrolling images too: PyPhoto (ahead)
        5. 10.5.5. Using Canvas Events
          1. 10.5.5.1. Binding events on specific items
      6. 10.6. Grids
        1. 10.6.1. Grid Basics
        2. 10.6.2. grid Versus pack
        3. 10.6.3. Combining grid and pack
        4. 10.6.4. Making Gridded Widgets Expandable
          1. 10.6.4.1. Resizing in grids
          2. 10.6.4.2. Spanning columns and rows
        5. 10.6.5. Laying Out Larger Tables with grid
      7. 10.7. Time Tools, Threads, and Animation
        1. 10.7.1. Using Threads with GUIs
        2. 10.7.2. Using the after Method
          1. 10.7.2.1. Hiding and redrawing widgets and windows
        3. 10.7.3. Simple Animation Techniques
          1. 10.7.3.1. Using time.sleep loops
          2. 10.7.3.2. Using widget.after events
          3. 10.7.3.3. Using multiple time.sleep loop threads
        4. 10.7.4. Other Animation Concepts: Threads and Toolkits
      8. 10.8. The End of the Tour
      9. 10.9. The PyDemos and PyGadgets Launchers
        1. 10.9.1. PyDemos Launcher Bar
        2. 10.9.2. PyGadgets Launcher Bar
    4. 11. GUI Coding Techniques
      1. 11.1. “Building a Better Mouse Trap”
      2. 11.2. GuiMixin: Common Tool Mixin Classes
      3. 11.3. GuiMaker: Automating Menus and Toolbars
        1. 11.3.1. Subclass Protocols
        2. 11.3.2. GuiMaker Classes
        3. 11.3.3. GuiMaker Self-Test
        4. 11.3.4. BigGui: A Client Demo Program
      4. 11.4. ShellGui: GUIs for Command-Line Tools
        1. 11.4.1. A Generic Shell-Tools Display
        2. 11.4.2. Application-Specific Tool Set Classes
        3. 11.4.3. Adding GUI Frontends to Command Lines
      5. 11.5. GuiStreams: Redirecting Streams to Widgets
        1. 11.5.1. Using Redirection for the Packing Scripts
      6. 11.6. Reloading Callback Handlers Dynamically
      7. 11.7. Wrapping Up Top-Level Window Interfaces
      8. 11.8. GUIs, Threads, and Queues
        1. 11.8.1. Placing Callbacks on Queues
      9. 11.9. More Ways to Add GUIs to Non-GUI Code
        1. 11.9.1. Popping up GUI Windows on Demand
        2. 11.9.2. Adding a GUI As a Separate Program: Sockets
        3. 11.9.3. Adding a GUI As a Separate Program: Pipes
    5. 12. Complete GUI Programs
      1. 12.1. “Python, Open Source, and Camaros”
        1. 12.1.1. Examples in Other Chapters
        2. 12.1.2. This Chapter’s Strategy
      2. 12.2. PyEdit: A Text Editor Program/Object
        1. 12.2.1. Running PyEdit
          1. 12.2.1.1. Menus and toolbars
          2. 12.2.1.2. Dialogs
          3. 12.2.1.3. Running program code
          4. 12.2.1.4. New features in version 2.0
        2. 12.2.2. PyEdit Source Code
      3. 12.3. PyPhoto: An Image Viewer and Resizer
        1. 12.3.1. Running PyPhoto
        2. 12.3.2. PyPhoto Source Code
      4. 12.4. PyView: An Image and Notes Slideshow
        1. 12.4.1. Running PyView
        2. 12.4.2. PyView Source Code
      5. 12.5. PyDraw: Painting and Moving Graphics
        1. 12.5.1. Running PyDraw
        2. 12.5.2. PyDraw Source Code
      6. 12.6. PyClock: An Analog/Digital Clock Widget
        1. 12.6.1. A Quick Geometry Lesson
        2. 12.6.2. Running PyClock
        3. 12.6.3. PyClock Source Code
      7. 12.7. PyToe: A Tic-Tac-Toe Game Widget
        1. 12.7.1. Running PyToe
        2. 12.7.2. PyToe Source Code (Book Examples Distribution)
      8. 12.8. Where to Go from Here
  8. IV. Internet Programming
    1. 13. Network Scripting
      1. 13.1. “Tune In, Log On, and Drop Out”
        1. 13.1.1. Internet Scripting Topics
          1. 13.1.1.1. What we will cover
          2. 13.1.1.2. What we won’t cover
          3. 13.1.1.3. Running examples in this part of the book
      2. 13.2. Plumbing the Internet
        1. 13.2.1. The Socket Layer
          1. 13.2.1.1. Machine identifiers
        2. 13.2.2. The Protocol Layer
          1. 13.2.2.1. Port number rules
          2. 13.2.2.2. Clients and servers
          3. 13.2.2.3. Protocol structures
        3. 13.2.3. Python’s Internet Library Modules
      3. 13.3. Socket Programming
        1. 13.3.1. Socket Basics
          1. 13.3.1.1. Server socket calls
          2. 13.3.1.2. Client socket calls
          3. 13.3.1.3. Running socket programs locally
          4. 13.3.1.4. Running socket programs remotely
          5. 13.3.1.5. Socket pragmatics
          6. 13.3.1.6. Spawning clients in parallel
          7. 13.3.1.7. Talking to reserved ports
      4. 13.4. Handling Multiple Clients
        1. 13.4.1. Forking Servers
          1. 13.4.1.1. Running the forking server
          2. 13.4.1.2. Forking processes
          3. 13.4.1.3. Exiting from children
          4. 13.4.1.4. Killing the zombies
          5. 13.4.1.5. Preventing zombies with signal handlers
        2. 13.4.2. Threading Servers
        3. 13.4.3. Standard Library Server Classes
        4. 13.4.4. Third-Party Server Tools: Twisted
        5. 13.4.5. Multiplexing Servers with select
          1. 13.4.5.1. A select-based echo server
          2. 13.4.5.2. Running the select server
        6. 13.4.6. Choosing a Server Scheme
      5. 13.5. A Simple Python File Server
        1. 13.5.1. Running the File Server and Clients
        2. 13.5.2. Adding a User-Interface Frontend
          1. 13.5.2.1. Using Frames and command lines
          2. 13.5.2.2. Using grids and function calls
          3. 13.5.2.3. Using a reusable form-layout class
    2. 14. Client-Side Scripting
      1. 14.1. “Socket to Me!”
      2. 14.2. FTP: Transferring Files over the Net
        1. 14.2.1. Fetching Files with ftplib
        2. 14.2.2. Using urllib to FTP Files
        3. 14.2.3. FTP get and put Utilities
          1. 14.2.3.1. Download utility
          2. 14.2.3.2. Upload utility
          3. 14.2.3.3. Playing the Monty Python theme song
          4. 14.2.3.4. Adding user interfaces
        4. 14.2.4. Downloading Web Sites (Mirrors)
        5. 14.2.5. Uploading Web Sites
        6. 14.2.6. Refactoring Uploads and Downloads for Reuse
          1. 14.2.6.1. Refactoring with functions
          2. 14.2.6.2. Refactoring with classes
        7. 14.2.7. Uploads and Deletes with Subdirectories
          1. 14.2.7.1. Uploading local trees
          2. 14.2.7.2. Deleting remote trees
      3. 14.3. Processing Internet Email
      4. 14.4. POP: Fetching Email
        1. 14.4.1. Mail Configuration Module
        2. 14.4.2. POP Mail Reader Script
        3. 14.4.3. Fetching Messages
        4. 14.4.4. Fetching Email at the Interactive Prompt
      5. 14.5. SMTP: Sending Email
        1. 14.5.1. SMTP Mail Sender Script
        2. 14.5.2. Sending Messages
        3. 14.5.3. More Ways to Abuse the Net
        4. 14.5.4. Back to the Big Internet Picture
        5. 14.5.5. Sending Email from the Interactive Prompt
      6. 14.6. email: Parsing and Composing Mails
        1. 14.6.1. Message Objects
        2. 14.6.2. Basic email Interfaces in Action
      7. 14.7. pymail: A Console-Based Email Client
        1. 14.7.1. Running the pymail Console Client
      8. 14.8. The mailtools Utility Package
        1. 14.8.1. Initialization File
        2. 14.8.2. MailTool Class
        3. 14.8.3. MailSender Class
        4. 14.8.4. MailFetcher Class
          1. 14.8.4.1. General usage
          2. 14.8.4.2. Inbox synchronization tools
        5. 14.8.5. MailParser Class
        6. 14.8.6. Self-Test Script
        7. 14.8.7. Updating the pymail Console Client
      9. 14.9. NNTP: Accessing Newsgroups
      10. 14.10. HTTP: Accessing Web Sites
      11. 14.11. Module urllib Revisited
        1. 14.11.1. Other urllib Interfaces
      12. 14.12. Other Client-Side Scripting Options
    3. 15. The PyMailGUI Client
      1. 15.1. “Use the Source, Luke”
        1. 15.1.1. Source Code Modules
        2. 15.1.2. Why PyMailGUI?
        3. 15.1.3. Running PyMailGUI
        4. 15.1.4. Presentation Strategy
        5. 15.1.5. New in This Edition
      2. 15.2. A PyMailGUI Demo
        1. 15.2.1. Getting Started
        2. 15.2.2. Loading Mail
        3. 15.2.3. Threading Model
        4. 15.2.4. Load Server Interface
        5. 15.2.5. Offline Processing with Save and Open
        6. 15.2.6. Sending Email and Attachments
        7. 15.2.7. Viewing Email and Attachments
        8. 15.2.8. Email Replies and Forwards
        9. 15.2.9. Deleting Email
        10. 15.2.10. POP Message Numbers and Synchronization
        11. 15.2.11. Multiple Windows and Status Messages
      3. 15.3. PyMailGUI Implementation
        1. 15.3.1. Code Reuse
        2. 15.3.2. Code Structure
        3. 15.3.3. PyMailGui2: The Main Module
        4. 15.3.4. SharedNames: Program-Wide Globals
        5. 15.3.5. ListWindows: Message List Windows
        6. 15.3.6. ViewWindows: Message View Windows
        7. 15.3.7. messagecache: Message Cache Manager
        8. 15.3.8. popuputil: General-Purpose GUI Pop Ups
        9. 15.3.9. wraplines: Line Split Tools
        10. 15.3.10. mailconfig: User Configurations
        11. 15.3.11. PyMailGuiHelp: User Help Text
        12. 15.3.12. Ideas for Improvement
    4. 16. Server-Side Scripting
      1. 16.1. “Oh What a Tangled Web We Weave”
      2. 16.2. What’s a Server-Side CGI Script?
        1. 16.2.1. The Script Behind the Curtain
        2. 16.2.2. Writing CGI Scripts in Python
      3. 16.3. Running Server-Side Examples
        1. 16.3.1. Web Server Options
        2. 16.3.2. Running a Local Web Server
        3. 16.3.3. The Server-Side Examples Root Page
        4. 16.3.4. Viewing Server-Side Examples and Output
      4. 16.4. Climbing the CGI Learning Curve
        1. 16.4.1. A First Web Page
          1. 16.4.1.1. HTML basics
          2. 16.4.1.2. Internet addresses (URLs)
          3. 16.4.1.3. Using minimal URLs
          4. 16.4.1.4. HTML file permission constraints
        2. 16.4.2. A First CGI Script
          1. 16.4.2.1. Installing CGI scripts
          2. 16.4.2.2. Finding Python on remote servers
        3. 16.4.3. Adding Pictures and Generating Tables
          1. 16.4.3.1. Table tags
        4. 16.4.4. Adding User Interaction
          1. 16.4.4.1. Submission page
          2. 16.4.4.2. More on form tags
          3. 16.4.4.3. Response script
          4. 16.4.4.4. Passing parameters in URLs
          5. 16.4.4.5. Testing outside browsers with the module urllib
        5. 16.4.5. Using Tables to Lay Out Forms
          1. 16.4.5.1. Converting strings in CGI scripts
          2. 16.4.5.2. Debugging CGI scripts
        6. 16.4.6. Adding Common Input Devices
        7. 16.4.7. Changing Input Layouts
          1. 16.4.7.1. Keeping display and logic separate
        8. 16.4.8. Passing Parameters in Hardcoded URLs
        9. 16.4.9. Passing Parameters in Hidden Form Fields
      5. 16.5. Saving State Information in CGI Scripts
        1. 16.5.1. URL Query Parameters
        2. 16.5.2. Hidden Form Input Fields
        3. 16.5.3. HTTP “Cookies”
          1. 16.5.3.1. Creating a cookie
          2. 16.5.3.2. Receiving a cookie
          3. 16.5.3.3. Using cookies in CGI scripts
          4. 16.5.3.4. Handling cookies with the module urllib2
        4. 16.5.4. Server-Side Databases
        5. 16.5.5. Extensions to the CGI Model
        6. 16.5.6. Combining Techniques
      6. 16.6. The Hello World Selector
        1. 16.6.1. Checking for Missing and Invalid Inputs
      7. 16.7. Refactoring Code for Maintainability
        1. 16.7.1. Step 1: Sharing Objects Between Pages—A New Input Form
        2. 16.7.2. Step 2: A Reusable Form Mock-Up Utility
        3. 16.7.3. Step 3: Putting It All Together—A New Reply Script
      8. 16.8. More on HTML and URL Escapes
        1. 16.8.1. URL Escape Code Conventions
        2. 16.8.2. Python HTML and URL Escape Tools
        3. 16.8.3. Escaping HTML Code
        4. 16.8.4. Escaping URLs
        5. 16.8.5. Escaping URLs Embedded in HTML Code
          1. 16.8.5.1. HTML and URL conflicts: &
          2. 16.8.5.2. Avoiding conflicts
      9. 16.9. Transferring Files to Clients and Servers
        1. 16.9.1. Displaying Arbitrary Server Files on the Client
          1. 16.9.1.1. Handling private files and errors
        2. 16.9.2. Uploading Client Files to the Server
          1. 16.9.2.1. Handling client path formats
        3. 16.9.3. More Than One Way to Push Bits over the Net
    5. 17. The PyMailCGI Server
      1. 17.1. “Things to Do When Visiting Chicago”
      2. 17.2. The PyMailCGI Web Site
        1. 17.2.1. Implementation Overview
        2. 17.2.2. New in This Edition
        3. 17.2.3. Presentation Overview
        4. 17.2.4. Running This Chapter’s Examples
      3. 17.3. The Root Page
        1. 17.3.1. Configuring PyMailCGI
      4. 17.4. Sending Mail by SMTP
        1. 17.4.1. The Message Composition Page
        2. 17.4.2. The Send Mail Script
        3. 17.4.3. Error Pages
        4. 17.4.4. Common Look-and-Feel
        5. 17.4.5. Using the Send Mail Script Outside a Browser
      5. 17.5. Reading POP Email
        1. 17.5.1. The POP Password Page
        2. 17.5.2. The Mail Selection List Page
        3. 17.5.3. Passing State Information in URL Link Parameters
        4. 17.5.4. Security Protocols
          1. 17.5.4.1. Reading mail with direct URLs
        5. 17.5.5. The Message View Page
        6. 17.5.6. Passing State Information in HTML Hidden Input Fields
        7. 17.5.7. Escaping Mail Text and Passwords in HTML
      6. 17.6. Processing Fetched Mail
        1. 17.6.1. Reply and Forward
        2. 17.6.2. Delete
        3. 17.6.3. Deletions and POP Message Numbers
          1. 17.6.3.1. Inbox synchronization error potential
          2. 17.6.3.2. Passing header text in hidden input fields (PyMailCGI_2.1)
          3. 17.6.3.3. Server-side files for headers
          4. 17.6.3.4. Delete on load
      7. 17.7. Utility Modules
        1. 17.7.1. External Components and Configuration
        2. 17.7.2. POP Mail Interface
        3. 17.7.3. POP Password Encryption
          1. 17.7.3.1. Manual data encryption: rotor (defunct)
          2. 17.7.3.2. Manual data encryption: PyCrypto
          3. 17.7.3.3. Secure HTTP transmissions
          4. 17.7.3.4. Secure cookies
          5. 17.7.3.5. The secret.py module
          6. 17.7.3.6. Rolling your own encryptor
        4. 17.7.4. Common Utilities Module
      8. 17.8. CGI Script Trade-Offs
        1. 17.8.1. Other Approaches
    6. 18. Advanced Internet Topics
      1. 18.1. “Surfing on the Shoulders of Giants”
      2. 18.2. Zope: A Web Application Framework
        1. 18.2.1. Zope Overview
          1. 18.2.1.1. Zope hierarchy model
          2. 18.2.1.2. Zope scripting
          3. 18.2.1.3. Zope components
        2. 18.2.2. Zope Object Publishing
        3. 18.2.3. A Zope External Method
          1. 18.2.3.1. Calling through the Web
          2. 18.2.3.2. Calling from other objects
        4. 18.2.4. A Simple Zope Interactive Web Site
      3. 18.3. HTMLgen: Web Pages from Objects
        1. 18.3.1. A Brief HTMLgen Tutorial
      4. 18.4. Jython: Python for Java
        1. 18.4.1. A Quick Introduction to Jython
        2. 18.4.2. Why Jython?
        3. 18.4.3. A Simple Jython Example
        4. 18.4.4. Interface Automation Tricks
        5. 18.4.5. Writing Java Applets in Jython
        6. 18.4.6. Jython Trade-Offs
        7. 18.4.7. Picking Your Python
      5. 18.5. Grail: A Python-Based Web Browser
        1. 18.5.1. A Simple Grail Applet Example
      6. 18.6. XML Processing Tools
        1. 18.6.1. A Brief Introduction to XML Parsing
      7. 18.7. Windows Web Scripting Extensions
        1. 18.7.1. Active Scripting: Client-Side Embedding
          1. 18.7.1.1. Active Scripting basics
          2. 18.7.1.2. Embedding Python in HTML
        2. 18.7.2. Active Server Pages: Server-Side Embedding
          1. 18.7.2.1. A short ASP example
        3. 18.7.3. The COM Connection
          1. 18.7.3.1. A brief introduction to COM
          2. 18.7.3.2. Python COM clients
          3. 18.7.3.3. Python COM servers
            1. 18.7.3.3.1. Using the Python server from a Python client
            2. 18.7.3.3.2. Using the Python server from a Visual Basic client
            3. 18.7.3.3.3. Using the Python server with client-side Active Scripting
          4. 18.7.3.4. The bigger COM picture: DCOM
      8. 18.8. Python Server Pages
        1. 18.8.1. PSP in Webware and mod_python
      9. 18.9. Rolling Your Own Servers in Python
        1. 18.9.1. Standard Library Socket Servers
        2. 18.9.2. Standard Library Web Servers
        3. 18.9.3. Third-Party Solutions
      10. 18.10. And Other Cool Stuff
  9. V. Tools and Techniques
    1. 19. Databases and Persistence
      1. 19.1. “Give Me an Order of Persistence, but Hold the Pickles”
      2. 19.2. Persistence Options in Python
      3. 19.3. DBM Files
        1. 19.3.1. Using DBM Files
      4. 19.4. Pickled Objects
        1. 19.4.1. Using Object Pickling
        2. 19.4.2. Picking in Action
        3. 19.4.3. Pickler Protocols and cPickle
      5. 19.5. Shelve Files
        1. 19.5.1. Using Shelves
        2. 19.5.2. Storing Built-In Object Types in Shelves
        3. 19.5.3. Storing Class Instances in Shelves
        4. 19.5.4. Changing Classes of Objects Stored in Shelves
        5. 19.5.5. Shelve Constraints
          1. 19.5.5.1. Keys must be strings
          2. 19.5.5.2. Objects are unique only within a key
          3. 19.5.5.3. Updates must treat shelves as fetch-modify-store mappings
          4. 19.5.5.4. Concurrent updates are not directly supported
          5. 19.5.5.5. Underlying DBM format portability
        6. 19.5.6. Pickled Class Constraints
        7. 19.5.7. Other Shelve Limitations
      6. 19.6. The ZODB Object-Oriented Database
        1. 19.6.1. A ZODB Tutorial
          1. 19.6.1.1. Installing ZODB
          2. 19.6.1.2. The ZEO distributed object server
          3. 19.6.1.3. Creating a ZODB database
          4. 19.6.1.4. Fetching and changing
        2. 19.6.2. Using Classes with ZODB
        3. 19.6.3. A ZODB People Database
        4. 19.6.4. ZODB Resources
      7. 19.7. SQL Database Interfaces
        1. 19.7.1. SQL Interface Overview
        2. 19.7.2. An SQL Database API Tutorial
          1. 19.7.2.1. The MySQL system
          2. 19.7.2.2. Installation
          3. 19.7.2.3. Getting started
          4. 19.7.2.4. Making databases and tables
          5. 19.7.2.5. Adding records
          6. 19.7.2.6. Running queries
          7. 19.7.2.7. Running updates
        3. 19.7.3. Building Record Dictionaries
          1. 19.7.3.1. Using table descriptions
          2. 19.7.3.2. Record dictionaries
          3. 19.7.3.3. Automating with scripts and modules
        4. 19.7.4. Tying the Pieces Together
        5. 19.7.5. Loading Database Tables from Files
          1. 19.7.5.1. Loading with SQL and Python
          2. 19.7.5.2. Python versus SQL
        6. 19.7.6. SQL Utility Scripts
          1. 19.7.6.1. Table load scripts
          2. 19.7.6.2. Table display script
          3. 19.7.6.3. Using the scripts
        7. 19.7.7. SQL Resources
      8. 19.8. PyForm: A Persistent Object Viewer
        1. 19.8.1. Processing Shelves with Code
        2. 19.8.2. Adding a Graphical Interface
        3. 19.8.3. PyForm GUI Implementation
        4. 19.8.4. PyForm Table Wrappers
        5. 19.8.5. PyForm Creation and View Utility Scripts
          1. 19.8.5.1. Creating and browsing custom databases
        6. 19.8.6. Data as Code
        7. 19.8.7. Browsing Other Kinds of Objects with PyForm
        8. 19.8.8. Browsing Other Kinds of Databases with PyForm
        9. 19.8.9. PyForm Limitations
    2. 20. Data Structures
      1. 20.1. “Roses Are Red, Violets Are Blue; Lists Are Mutable, and So Is Set Foo”
      2. 20.2. Implementing Stacks
        1. 20.2.1. A Stack Module
        2. 20.2.2. A Stack Class
        3. 20.2.3. Customization: Performance Monitors
        4. 20.2.4. Optimization: Tuple Tree Stacks
        5. 20.2.5. Optimization: In-Place List Modifications
        6. 20.2.6. Timing the Improvements
          1. 20.2.6.1. Results under Python 1.5.2
          2. 20.2.6.2. Results under Python 2.4
      3. 20.3. Implementing Sets
        1. 20.3.1. Set Functions
          1. 20.3.1.1. Supporting multiple operands
        2. 20.3.2. Set Classes
        3. 20.3.3. Optimization: Moving Sets to Dictionaries
          1. 20.3.3.1. Timing the results under Python 2.4
          2. 20.3.3.2. Timing results under Python 1.5.2: version skew
          3. 20.3.3.3. Using the Python profiler
        4. 20.3.4. Optimizing fastset by Coding Techniques (or Not)
        5. 20.3.5. Adding Relational Algebra to Sets (External)
      4. 20.4. Subclassing Built-In Types
      5. 20.5. Binary Search Trees
      6. 20.6. Graph Searching
        1. 20.6.1. Moving Graphs to Classes
      7. 20.7. Reversing Sequences
      8. 20.8. Permuting Sequences
      9. 20.9. Sorting Sequences
        1. 20.9.1. Adding Comparison Functions
      10. 20.10. Data Structures Versus Python Built-Ins
      11. 20.11. PyTree: A Generic Tree Object Viewer
        1. 20.11.1. Running PyTree
        2. 20.11.2. PyTree Source Code
          1. 20.11.2.1. Tree-independent GUI implementation
          2. 20.11.2.2. Tree wrappers and test widgets
        3. 20.11.3. PyTree Does Parse Trees Too
    3. 21. Text and Language
      1. 21.1. “See Jack Hack. Hack, Jack, Hack”
      2. 21.2. Strategies for Parsing Text in Python
      3. 21.3. String Method Utilities
        1. 21.3.1. Templating with Replacements and Formats
        2. 21.3.2. Parsing with Splits and Joins
        3. 21.3.3. Summing Columns in a File
        4. 21.3.4. Parsing and Unparsing Rule Strings
        5. 21.3.5. More on the holmes Expert System Shell
      4. 21.4. Regular Expression Pattern Matching
        1. 21.4.1. First Examples
        2. 21.4.2. Using the re Module
          1. 21.4.2.1. Module functions
          2. 21.4.2.2. Compiled pattern objects
          3. 21.4.2.3. Match objects
          4. 21.4.2.4. Regular expression patterns
        3. 21.4.3. Basic Patterns
        4. 21.4.4. Scanning C Header Files for Patterns
        5. 21.4.5. A File Pattern Search Utility
      5. 21.5. Advanced Language Tools
      6. 21.6. Handcoded Parsers
        1. 21.6.1. The Expression Grammar
        2. 21.6.2. The Parser’s Code
        3. 21.6.3. Adding a Parse Tree Interpreter
        4. 21.6.4. Parse Tree Structure
        5. 21.6.5. Exploring Parse Trees with PyTree
        6. 21.6.6. Parsers Versus Python
      7. 21.7. PyCalc: A Calculator Program/Object
        1. 21.7.1. A Simple Calculator GUI
          1. 21.7.1.1. Building the GUI
          2. 21.7.1.2. Running code strings
          3. 21.7.1.3. Extending and attaching
        2. 21.7.2. PyCalc—A Real Calculator GUI
          1. 21.7.2.1. Running PyCalc
          2. 21.7.2.2. Evaluating expressions with stacks
          3. 21.7.2.3. PyCalc source code
          4. 21.7.2.4. Using PyCalc as a component
          5. 21.7.2.5. Adding new buttons in new components
  10. VI. Integration
    1. 22. Extending Python
      1. 22.1. “I Am Lost at C”
      2. 22.2. Integration Modes
        1. 22.2.1. Presentation Notes
      3. 22.3. C Extensions Overview
      4. 22.4. A Simple C Extension Module
      5. 22.5. Extension Module Details
        1. 22.5.1. Compilation and Linking
          1. 22.5.1.1. Dynamic binding
          2. 22.5.1.2. Static binding
          3. 22.5.1.3. Static versus dynamic binding
        2. 22.5.2. Compiling with the Distutils System
        3. 22.5.3. Anatomy of a C Extension Module
        4. 22.5.4. Data Conversions
          1. 22.5.4.1. Python to C: using Python argument lists
          2. 22.5.4.2. Python to C: using Python return values
          3. 22.5.4.3. C to Python: returning values to Python
          4. 22.5.4.4. Common conversion codes
        5. 22.5.5. Error Handling
          1. 22.5.5.1. Raising Python exceptions in C
          2. 22.5.5.2. Detecting errors that occur in Python
        6. 22.5.6. Reference Counts
        7. 22.5.7. Other Extension Tasks: Threads
      6. 22.6. The SWIG Integration Code Generator
        1. 22.6.1. A Simple SWIG Example
        2. 22.6.2. SWIG Details
      7. 22.7. Wrapping C Environment Calls
        1. 22.7.1. Adding Wrapper Classes to Flat Libraries
        2. 22.7.2. But Don’t Do That Either—SWIG
      8. 22.8. A C Extension Module String Stack
        1. 22.8.1. But Don’t Do That Either—SWIG
      9. 22.9. A C Extension Type String Stack
        1. 22.9.1. Anatomy of a C Extension Type
        2. 22.9.2. Compiling and Running
        3. 22.9.3. Timing the C Implementations
        4. 22.9.4. Older Timing Results
        5. 22.9.5. But Don’t Do That Either—SWIG
      10. 22.10. Wrapping C++ Classes with SWIG
        1. 22.10.1. A Simple C++ Extension Class
        2. 22.10.2. Wrapping the C++ Class with SWIG
        3. 22.10.3. Using the C++ Class in Python
          1. 22.10.3.1. Using the low-level extension module
          2. 22.10.3.2. Subclassing the C++ class in Python
          3. 22.10.3.3. Exploring the wrappers interactively
      11. 22.11. Other Extending Tools
    2. 23. Embedding Python
      1. 23.1. “Add Python. Mix Well. Repeat.”
      2. 23.2. C Embedding API Overview
        1. 23.2.1. What Is Embedded Code?
      3. 23.3. Basic Embedding Techniques
        1. 23.3.1. Running Simple Code Strings
          1. 23.3.1.1. Compiling and running
        2. 23.3.2. Running Code Strings with Results and Namespaces
        3. 23.3.3. Calling Python Objects
        4. 23.3.4. Running Strings in Dictionaries
        5. 23.3.5. Precompiling Strings to Bytecode
      4. 23.4. Registering Callback Handler Objects
      5. 23.5. Using Python Classes in C
      6. 23.6. A High-Level Embedding API: ppembed
        1. 23.6.1. Running Objects with ppembed
        2. 23.6.2. Running Code Strings with ppembed
        3. 23.6.3. Running Customizable Validations
          1. 23.6.3.1. Running function-based validations
          2. 23.6.3.2. Other validation components
        4. 23.6.4. ppembed Implementation
        5. 23.6.5. Other Integration Examples (External)
      7. 23.7. Other Integration Topics
        1. 23.7.1. Jython: Java Integration
        2. 23.7.2. IronPython: C#/.NET Integration
        3. 23.7.3. COM Integration on Windows
        4. 23.7.4. CORBA Integration
        5. 23.7.5. Other Languages
        6. 23.7.6. Network-Based Integration Protocols
        7. 23.7.7. Integration Versus Optimization
          1. 23.7.7.1. Framework roles
          2. 23.7.7.2. Extension module roles
          3. 23.7.7.3. Picking an integration technology
  11. VIII. The End
    1. 24. Conclusion: Python and the Development Cycle
      1. 24.1. “That’s the End of the Book, Now Here’s the Meaning of Life”
      2. 24.2. “Something’s Wrong with the Way We Program Computers”
      3. 24.3. The “Gilligan Factor”
      4. 24.4. Doing the Right Thing
        1. 24.4.1. The Static Language Build Cycle
        2. 24.4.2. Artificial Complexities
        3. 24.4.3. One Language Does Not Fit All
      5. 24.5. Enter Python
      6. 24.6. But What About That Bottleneck?
        1. 24.6.1. Python Provides Immediate Turnaround
        2. 24.6.2. Python Is “Executable Pseudocode”
        3. 24.6.3. Python Is OOP Done Right
        4. 24.6.4. Python Fosters Hybrid Applications
      7. 24.7. On Sinking the Titanic
      8. 24.8. So What’s “Python: The Sequel”?
      9. 24.9. In the Final Analysis . . .
      10. 24.10. Postscript to the Second Edition (2000)
        1. 24.10.1. Integration Isn’t Everything
        2. 24.10.2. The End of the Java Wars
        3. 24.10.3. We’re Not Off That Island Yet
      11. 24.11. Postscript to the Third Edition (2006)
        1. 24.11.1. Proof of Concept
        2. 24.11.2. Integration Today
        3. 24.11.3. Quality Counts
  12. Index
  13. Colophon
  14. Copyright

Product information

  • Title: Programming Python, 3rd Edition
  • Author(s): Mark Lutz
  • Release date: August 2006
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9780596009250