Table of Contents
Preface; “And Now for Something Completely Different…”; About This Book; About This Fourth Edition; What’s Left, Then?; Python 3.X Impacts on This Book; Using Book Examples; Contacting O’Reilly; Conventions Used in This Book; Acknowledgments; The Beginning; Chapter 1: A Sneak Preview; 1.1 “Programming Python: The Short Story”; 1.2 The Task; 1.3 Step 1: Representing Records; 1.4 Step 2: Storing Records Persistently; 1.5 Step 3: Stepping Up to OOP; 1.6 Step 4: Adding Console Interaction; 1.7 Step 5: Adding a GUI; 1.8 Step 6: Adding a Web Interface; 1.9 The End of the Demo; System Programming; Chapter 2: System Tools; 2.1 “The os.path to Knowledge”; 2.2 System Scripting Overview; 2.3 Introducing the sys Module; 2.4 Introducing the os Module; Chapter 3: Script Execution Context; 3.1 “I’d Like to Have an Argument, Please”; 3.2 Current Working Directory; 3.3 Command-Line Arguments; 3.4 Shell Environment Variables; 3.5 Standard Streams; Chapter 4: File and Directory Tools; 4.1 “Erase Your Hard Drive in Five Easy Steps!”; 4.2 File Tools; 4.3 Directory Tools; Chapter 5: Parallel System Tools; 5.1 “Telling the Monkeys What to Do”; 5.2 Forking Processes; 5.3 Threads; 5.4 Program Exits; 5.5 Interprocess Communication; 5.6 The multiprocessing Module; 5.7 Other Ways to Start Programs; 5.8 A Portable Program-Launch Framework; 5.9 Other System Tools Coverage; Chapter 6: Complete System Programs; 6.1 “The Greps of Wrath”; 6.2 A Quick Game of “Find the Biggest Python File”; 6.3 Splitting and Joining Files; 6.4 Generating Redirection Web Pages; 6.5 A Regression Test Script; 6.6 Copying Directory Trees; 6.7 Comparing Directory Trees; 6.8 Searching Directory Trees; 6.9 Visitor: Walking Directories “++”; 6.10 Playing Media Files; 6.11 Automated Program Launchers (External); GUI Programming; Chapter 7: Graphical User Interfaces; 7.1 “Here’s Looking at You, Kid”; 7.2 Python GUI Development Options; 7.3 tkinter Overview; 7.4 Climbing the GUI Learning Curve; 7.5 tkinter Coding Alternatives; 7.6 Adding Buttons and Callbacks; 7.7 Adding User-Defined Callback Handlers; 7.8 Adding Multiple Widgets; 7.9 Customizing Widgets with Classes; 7.10 Reusable GUI Components with Classes; 7.11 The End of the Tutorial; 7.12 Python/tkinter for Tcl/Tk Converts; Chapter 8: A tkinter Tour, Part 1; 8.1 “Widgets and Gadgets and GUIs, Oh My!”; 8.2 Configuring Widget Appearance; 8.3 Top-Level Windows; 8.4 Dialogs; 8.5 Binding Events; 8.6 Message and Entry; 8.7 Checkbutton, Radiobutton, and Scale; 8.8 Running GUI Code Three Ways; 8.9 Images; 8.10 Viewing and Processing Images with PIL; Chapter 9: A tkinter Tour, Part 2; 9.1 “On Today’s Menu: Spam, Spam, and Spam”; 9.2 Menus; 9.3 Listboxes and Scrollbars; 9.4 Text; 9.5 Canvas; 9.6 Grids; 9.7 Time Tools, Threads, and Animation; 9.8 The End of the Tour; Chapter 10: GUI Coding Techniques; 10.1 “Building a Better Mousetrap”; 10.2 GuiMixin: Common Tool Mixin Classes; 10.3 GuiMaker: Automating Menus and Toolbars; 10.4 ShellGui: GUIs for Command-Line Tools; 10.5 GuiStreams: Redirecting Streams to Widgets; 10.6 Reloading Callback Handlers Dynamically; 10.7 Wrapping Up Top-Level Window Interfaces; 10.8 GUIs, Threads, and Queues; 10.9 More Ways to Add GUIs to Non-GUI Code; 10.10 The PyDemos and PyGadgets Launchers; Chapter 11: Complete GUI Programs; 11.1 “Python, Open Source, and Camaros”; 11.2 PyEdit: A Text Editor Program/Object; 11.3 PyPhoto: An Image Viewer and Resizer; 11.4 PyView: An Image and Notes Slideshow; 11.5 PyDraw: Painting and Moving Graphics; 11.6 PyClock: An Analog/Digital Clock Widget; 11.7 PyToe: A Tic-Tac-Toe Game Widget; 11.8 Where to Go from Here; Internet Programming; Chapter 12: Network Scripting; 12.1 “Tune In, Log On, and Drop Out”; 12.2 Python Internet Development Options; 12.3 Plumbing the Internet; 12.4 Socket Programming; 12.5 Handling Multiple Clients; 12.6 Making Sockets Look Like Files and Streams; 12.7 A Simple Python File Server; Chapter 13: Client-Side Scripting; 13.1 “Socket to Me!”; 13.2 FTP: Transferring Files over the Net; 13.3 Transferring Files with ftplib; 13.4 Transferring Directories with ftplib; 13.5 Transferring Directory Trees with ftplib; 13.6 Processing Internet Email; 13.7 POP: Fetching Email; 13.8 SMTP: Sending Email; 13.9 email: Parsing and Composing Mail Content; 13.10 A Console-Based Email Client; 13.11 The mailtools Utility Package; 13.12 NNTP: Accessing Newsgroups; 13.13 HTTP: Accessing Websites; 13.14 The urllib Package Revisited; 13.15 Other Client-Side Scripting Options; Chapter 14: The PyMailGUI Client; 14.1 “Use the Source, Luke”; 14.2 Major PyMailGUI Changes; 14.3 A PyMailGUI Demo; 14.4 PyMailGUI Implementation; 14.5 Ideas for Improvement; Chapter 15: Server-Side Scripting; 15.1 “Oh, What a Tangled Web We Weave”; 15.2 What’s a Server-Side CGI Script?; 15.3 Running Server-Side Examples; 15.4 Climbing the CGI Learning Curve; 15.5 Saving State Information in CGI Scripts; 15.6 The Hello World Selector; 15.7 Refactoring Code for Maintainability; 15.8 More on HTML and URL Escapes; 15.9 Transferring Files to Clients and Servers; Chapter 16: The PyMailCGI Server; 16.1 “Things to Do When Visiting Chicago”; 16.2 The PyMailCGI Website; 16.3 The Root Page; 16.4 Sending Mail by SMTP; 16.5 Reading POP Email; 16.6 Processing Fetched Mail; 16.7 Utility Modules; 16.8 Web Scripting Trade-Offs; Tools and Techniques; Chapter 17: Databases and Persistence; 17.1 “Give Me an Order of Persistence, but Hold the Pickles”; 17.2 Persistence Options in Python; 17.3 DBM Files; 17.4 Pickled Objects; 17.5 Shelve Files; 17.6 The ZODB Object-Oriented Database; 17.7 SQL Database Interfaces; 17.8 ORMs: Object Relational Mappers; 17.9 PyForm: A Persistent Object Viewer (External); Chapter 18: Data Structures; 18.1 “Roses Are Red, Violets Are Blue; Lists Are Mutable, and So Is Set Foo”; 18.2 Implementing Stacks; 18.3 Implementing Sets; 18.4 Subclassing Built-in Types; 18.5 Binary Search Trees; 18.6 Graph Searching; 18.7 Permuting Sequences; 18.8 Reversing and Sorting Sequences; 18.9 PyTree: A Generic Tree Object Viewer; Chapter 19: Text and Language; 19.1 “See Jack Hack. Hack, Jack, Hack”; 19.2 Strategies for Processing Text in Python; 19.3 String Method Utilities; 19.4 Regular Expression Pattern Matching; 19.5 XML and HTML Parsing; 19.6 Advanced Language Tools; 19.7 Custom Language Parsers; 19.8 PyCalc: A Calculator Program/Object; Chapter 20: Python/C Integration; 20.1 “I Am Lost at C”; 20.2 Extending Python in C: Overview; 20.3 A Simple C Extension Module; 20.4 The SWIG Integration Code Generator; 20.5 Wrapping C Environment Calls; 20.6 Wrapping C++ Classes with SWIG; 20.7 Other Extending Tools; 20.8 Embedding Python in C: Overview; 20.9 Basic Embedding Techniques; 20.10 Registering Callback Handler Objects; 20.11 Using Python Classes in C; 20.12 Other Integration Topics; The End; Chapter 21: Conclusion: Python and the Development Cycle; 21.1 “That’s the End of the Book, Now Here’s the Meaning of Life”; 21.2 “Something’s Wrong with the Way We Program Computers”; 21.3 The “Gilligan Factor”; 21.4 Doing the Right Thing; 21.5 Enter Python; 21.6 But What About That Bottleneck?; 21.7 On Sinking the Titanic; 21.8 “So What’s Python?”: The Sequel; 21.9 In the Final Analysis…; Colophon;