Synopses & Reviews
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."
As a language optimized for developer productivity, Python solves the software development crunch -- programmers can do more in less time, without sacrificing code quality. Programming Python, 3rd edition is a comprehensive book that shows you how you can apply Python in real-world problem domains such as GUI programming, Internet scripting, parallel processing, database management, networked applications, and more.
As the industry standard book for mastering this expedient language, Programming Python also focuses on teaching you the right way to code: a good programmer knows that he or she must write code for both the computer and for other human readers. This book explains Python language syntax and programming techniques in a clear and concise manner, with numerous examples that illustrate both correct usage and common idioms. If you're interested in Python programming, you will want this wealth of practical advice, snippets of code, and patterns of program design that can be directly lifted out of the book and applied to everyday programming problems. This 3rd edition is revised and updated for the myriad of changes that came in the 2.4 version.
Once you've come to grips with the core Python language, learning how to build Python applications presents a far more interesting challenge. Tap this book's wealth of practical advice, snippets of code, and patterns of program design to take your Python skills to the next level.
You'll start with in-depth discussions of core concepts and then progress toward complete programs in different application domains, including:
- GUI programming
- Internet scripting
- Parallel processing
- Database management
- Networked applications
- System administration
- Text processing
Most programming experts consider this classic book, now updated for Python 3.x, to be the industry standard for learning Python application programming. With clear and concise explanations of Python syntax and programming techniques, and numerous examples that illustrate both correct usage and common idioms, Programming Python shows you the right way to code with Python.
With this convenient, single-source reference, you'll learn how to develop instrumentation software with Python that lets you monitor or control devices in the physical world. Whether you need to acquire data from a hardware device or automate its functions, this book shows you how to build interfaces that include everything from software to wiring. You get step-by-step instructions, clear examples, and hands-on tips and hints for interfacing a PC to the real world, along with advice to help you avoid common pitfalls.
Use the book's hardware survey to discover the interface type for your particular device, and then follow detailed examples to develop the interface with Python and C. Organized by interface type, data processing activities, and user interface implementations, this book is for anyone who works with instrumentation, robotics, data acquisition, or process control.
- Understand how to define the scope of an application and determine the algorithms necessary -- and why it's important
- Learn how to use industry-standard interfaces such as RS-232, RS-485, and GPIB
- Create low-level extension modules in C to interface Python with a variety of hardware and test instruments
- Explore the console, curses, TkInter, and wxPython for graphical and text-based user interfaces
- Use open source software tools and libraries to reduce cost and avoid implementing functionality from scratch
As a language optimized for developer productivity, Python solves the software development crunch. As the industry standard book for mastering this expedient language, this volume explains Python language syntax and programming techniques in a clear and concise manner, with numerous examples that illustrate both correct usage and common idioms.
If you've mastered Python's fundamentals, you're ready to start using it to get real work done. Programming Python will show you how, with in-depth tutorials on the language's primary application domains: system administration, GUIs, and the Web. You'll also explore how Python is used in databases, networking, front-end scripting layers, text processing, and more. This book focuses on commonly used tools and libraries to give you a comprehensive understanding of Pythons many roles in practical, real-world programming.
You'll learn language syntax and programming techniques in a clear and concise manner, with lots of examples that illustrate both correct usage and common idioms. Completely updated for version 3.x, Programming Python also delves into the language as a software development tool, with many code examples scaled specifically for that purpose.
- Quick Python tour: Build a simple demo that includes data representation, object-oriented programming, object persistence, GUIs, and website basics
- System programming: Explore system interface tools and techniques for command-line scripting, processing files and folders, running programs in parallel, and more
- GUI programming: Learn to use Pythons tkinter widget library
- Internet programming: Access client-side network protocols and email tools, use CGI scripts, and learn website implementation techniques
- More ways to apply Python: Implement data structures, parse text-based information, interface with databases, and extend and embed Python
About the Author
Mark Lutz is the world leader in Python training, the author of Python's earliest and best-selling texts, and a pioneering figure in the Python community since 1992. He is also the author of O'Reilly's Programming Python, 3rd Edition and Python Pocket Reference, 3rd Edition. Mark began teaching Python classes in 1997, and has instructed more than 200 Python training sessions as of 2007. Mark also has BS and MS degrees in Computer Science and 25 years of software development experience. Whenever Mark gets a break from spreading the Python word, he leads an ordinary, average life with his kids in Colorado. Mark can be reached by email at , or on the web at http://www.rmi.net/~lutz.
Table of Contents
Foreword; How Time Flies!; Coming Attractions; Concluding Remarks; Foreword to the Second Edition (2001); Foreword from the First Edition (1996); Preface; "And Now for Something Completely Different . . . Again"; About This Book; About This Edition; This Book's Motivation; This Book's Structure; This Edition's Design; Using the Book's Examples; Conventions Used in This Book; Safari® Enabled; Where to Look for Updates; Contacting O'Reilly; Using Code Examples; Acknowledgments; Part I: The Beginning; Chapter 1: Introducing Python; 1.1 "And Now for Something Completely Different"; 1.2 Python Philosophy 101; 1.3 The Life of Python; 1.4 Signs of the Python Times; 1.5 The Compulsory Features List; 1.6 What's Python Good For?; 1.7 What's Python Not Good For?; 1.8 Truth in Advertising; Chapter 2: A Sneak Preview; 2.1 "Programming Python: The Short Story"; 2.2 The Task; 2.3 Step 1: Representing Records; 2.4 Step 2: Storing Records Persistently; 2.5 Step 3: Stepping Up to OOP; 2.6 Step 4: Adding Console Interaction; 2.7 Step 5: Adding a GUI; 2.8 Step 6: Adding a Web Interface; 2.9 The End of the Demo; Part II: System Programming; Chapter 3: System Tools; 3.1 "The os.path to Knowledge"; 3.2 System Scripting Overview; 3.3 Introducing the sys Module; 3.4 Introducing the os Module; 3.5 Script Execution Context; 3.6 Current Working Directory; 3.7 Command-Line Arguments; 3.8 Shell Environment Variables; 3.9 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 Pipes; 5.7 Signals; 5.8 Other Ways to Start Programs; 5.9 A Portable Program-Launch Framework; 5.10 Other System Tools; Chapter 6: System Examples: Utilities; 6.1 "Splits and Joins and Alien Invasions"; 6.2 Splitting and Joining Files; 6.3 Generating Forward-Link Web Pages; 6.4 A Regression Test Script; 6.5 Packing and Unpacking Files; 6.6 Automated Program Launchers; Chapter 7: System Examples: Directories; 7.1 "The Greps of Wrath"; 7.2 Fixing DOS Line Ends; 7.3 Fixing DOS Filenames; 7.4 Searching Directory Trees; 7.5 Visitor: Walking Trees Generically; 7.6 Copying Directory Trees; 7.7 Deleting Directory Trees; 7.8 Comparing Directory Trees; Part III: GUI Programming; Chapter 8: Graphical User Interfaces; 8.1 "Here's Looking at You, Kid"; 8.2 Python GUI Development Options; 8.3 Tkinter Overview; 8.4 Climbing the GUI Learning Curve; 8.5 Tkinter Coding Basics; 8.6 Tkinter Coding Alternatives; 8.7 Adding Buttons and Callbacks; 8.8 Adding User-Defined Callback Handlers; 8.9 Adding Multiple Widgets; 8.10 Customizing Widgets with Classes; 8.11 Reusable GUI Components with Classes; 8.12 The End of the Tutorial; 8.13 Python/Tkinter for Tcl/Tk Converts; Chapter 9: A Tkinter Tour, Part 1; 9.1 "Widgets and Gadgets and GUIs, Oh My!"; 9.2 Configuring Widget Appearance; 9.3 Top-Level Windows; 9.4 Dialogs; 9.5 Binding Events; 9.6 Message and Entry; 9.7 Checkbutton, Radiobutton, and Scale; 9.8 Running GUI Code Three Ways; 9.9 Images; 9.10 Viewing and Processing Images with PIL; Chapter 10: A Tkinter Tour, Part 2; 10.1 "On Today's Menu: Spam, Spam, and Spam"; 10.2 Menus; 10.3 Listboxes and Scrollbars; 10.4 Text; 10.5 Canvas; 10.6 Grids; 10.7 Time Tools, Threads, and Animation; 10.8 The End of the Tour; 10.9 The PyDemos and PyGadgets Launchers; Chapter 11: GUI Coding Techniques; 11.1 "Building a Better Mouse Trap"; 11.2 GuiMixin: Common Tool Mixin Classes; 11.3 GuiMaker: Automating Menus and Toolbars; 11.4 ShellGui: GUIs for Command-Line Tools; 11.5 GuiStreams: Redirecting Streams to Widgets; 11.6 Reloading Callback Handlers Dynamically; 11.7 Wrapping Up Top-Level Window Interfaces; 11.8 GUIs, Threads, and Queues; 11.9 More Ways to Add GUIs to Non-GUI Code; Chapter 12: Complete GUI Programs; 12.1 "Python, Open Source, and Camaros"; 12.2 PyEdit: A Text Editor Program/Object; 12.3 PyPhoto: An Image Viewer and Resizer; 12.4 PyView: An Image and Notes Slideshow; 12.5 PyDraw: Painting and Moving Graphics; 12.6 PyClock: An Analog/Digital Clock Widget; 12.7 PyToe: A Tic-Tac-Toe Game Widget; 12.8 Where to Go from Here; Part IV: Internet Programming; Chapter 13: Network Scripting; 13.1 "Tune In, Log On, and Drop Out"; 13.2 Plumbing the Internet; 13.3 Socket Programming; 13.4 Handling Multiple Clients; 13.5 A Simple Python File Server; Chapter 14: Client-Side Scripting; 14.1 "Socket to Me!"; 14.2 FTP: Transferring Files over the Net; 14.3 Processing Internet Email; 14.4 POP: Fetching Email; 14.5 SMTP: Sending Email; 14.6 email: Parsing and Composing Mails; 14.7 pymail: A Console-Based Email Client; 14.8 The mailtools Utility Package; 14.9 NNTP: Accessing Newsgroups; 14.10 HTTP: Accessing Web Sites; 14.11 Module urllib Revisited; 14.12 Other Client-Side Scripting Options; Chapter 15: The PyMailGUI Client; 15.1 "Use the Source, Luke"; 15.2 A PyMailGUI Demo; 15.3 PyMailGUI Implementation; Chapter 16: Server-Side Scripting; 16.1 "Oh What a Tangled Web We Weave"; 16.2 What's a Server-Side CGI Script?; 16.3 Running Server-Side Examples; 16.4 Climbing the CGI Learning Curve; 16.5 Saving State Information in CGI Scripts; 16.6 The Hello World Selector; 16.7 Refactoring Code for Maintainability; 16.8 More on HTML and URL Escapes; 16.9 Transferring Files to Clients and Servers; Chapter 17: The PyMailCGI Server; 17.1 "Things to Do When Visiting Chicago"; 17.2 The PyMailCGI Web Site; 17.3 The Root Page; 17.4 Sending Mail by SMTP; 17.5 Reading POP Email; 17.6 Processing Fetched Mail; 17.7 Utility Modules; 17.8 CGI Script Trade-Offs; Chapter 18: Advanced Internet Topics; 18.1 "Surfing on the Shoulders of Giants"; 18.2 Zope: A Web Application Framework; 18.3 HTMLgen: Web Pages from Objects; 18.4 Jython: Python for Java; 18.5 Grail: A Python-Based Web Browser; 18.6 XML Processing Tools; 18.7 Windows Web Scripting Extensions; 18.8 Python Server Pages; 18.9 Rolling Your Own Servers in Python; 18.10 And Other Cool Stuff; Part V: Tools and Techniques; Chapter 19: Databases and Persistence; 19.1 "Give Me an Order of Persistence, but Hold the Pickles"; 19.2 Persistence Options in Python; 19.3 DBM Files; 19.4 Pickled Objects; 19.5 Shelve Files; 19.6 The ZODB Object-Oriented Database; 19.7 SQL Database Interfaces; 19.8 PyForm: A Persistent Object Viewer; Chapter 20: Data Structures; 20.1 "Roses Are Red, Violets Are Blue; Lists Are Mutable, and So Is Set Foo"; 20.2 Implementing Stacks; 20.3 Implementing Sets; 20.4 Subclassing Built-In Types; 20.5 Binary Search Trees; 20.6 Graph Searching; 20.7 Reversing Sequences; 20.8 Permuting Sequences; 20.9 Sorting Sequences; 20.10 Data Structures Versus Python Built-Ins; 20.11 PyTree: A Generic Tree Object Viewer; Chapter 21: Text and Language; 21.1 "See Jack Hack. Hack, Jack, Hack"; 21.2 Strategies for Parsing Text in Python; 21.3 String Method Utilities; 21.4 Regular Expression Pattern Matching; 21.5 Advanced Language Tools; 21.6 Handcoded Parsers; 21.7 PyCalc: A Calculator Program/Object; Part VI: Integration; Chapter 22: Extending Python; 22.1 "I Am Lost at C"; 22.2 Integration Modes; 22.3 C Extensions Overview; 22.4 A Simple C Extension Module; 22.5 Extension Module Details; 22.6 The SWIG Integration Code Generator; 22.7 Wrapping C Environment Calls; 22.8 A C Extension Module String Stack; 22.9 A C Extension Type String Stack; 22.10 Wrapping C++ Classes with SWIG; 22.11 Other Extending Tools; Chapter 23: Embedding Python; 23.1 "Add Python. Mix Well. Repeat."; 23.2 C Embedding API Overview; 23.3 Basic Embedding Techniques; 23.4 Registering Callback Handler Objects; 23.5 Using Python Classes in C; 23.6 A High-Level Embedding API: ppembed; 23.7 Other Integration Topics; Part VIII: The End; Chapter 24: Conclusion: Python and the Development Cycle; 24.1 "That's the End of the Book, Now Here's the Meaning of Life"; 24.2 "Something's Wrong with the Way We Program Computers"; 24.3 The "Gilligan Factor"; 24.4 Doing the Right Thing; 24.5 Enter Python; 24.6 But What About That Bottleneck?; 24.7 On Sinking the Titanic; 24.8 So What's "Python: The Sequel"?; 24.9 In the Final Analysis . . .; 24.10 Postscript to the Second Edition (2000); 24.11 Postscript to the Third Edition (2006); Colophon;