Book description
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 Python’s 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.
Topics include:
- 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 Python’s 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
Table of contents
- A Note Regarding Supplemental Files
- Preface
- I. The Beginning
-
II. System Programming
- 2. System Tools
-
3. Script Execution Context
- “I’d Like to Have an Argument, Please”
- Current Working Directory
- Command-Line Arguments
- Shell Environment Variables
- Standard Streams
-
4. File and Directory Tools
- “Erase Your Hard Drive in Five Easy Steps!”
- File Tools
- Directory Tools
-
5. Parallel System Tools
- “Telling the Monkeys What to Do”
- Forking Processes
- Threads
- Program Exits
- Interprocess Communication
- The multiprocessing Module
- Other Ways to Start Programs
- A Portable Program-Launch Framework
- Other System Tools Coverage
-
6. Complete System Programs
- “The Greps of Wrath”
- A Quick Game of “Find the Biggest Python File”
- Splitting and Joining Files
- Generating Redirection Web Pages
- A Regression Test Script
- Copying Directory Trees
- Comparing Directory Trees
- Searching Directory Trees
- Visitor: Walking Directories “++”
- Playing Media Files
- Automated Program Launchers (External)
-
III. GUI Programming
-
7. Graphical User Interfaces
- “Here’s Looking at You, Kid”
- Python GUI Development Options
- tkinter Overview
- Climbing the GUI Learning Curve
- tkinter Coding Alternatives
- Adding Buttons and Callbacks
- Adding User-Defined Callback Handlers
- Adding Multiple Widgets
- Customizing Widgets with Classes
- Reusable GUI Components with Classes
- The End of the Tutorial
- Python/tkinter for Tcl/Tk Converts
-
8. A tkinter Tour, Part 1
- “Widgets and Gadgets and GUIs, Oh My!”
- Configuring Widget Appearance
- Top-Level Windows
- Dialogs
- Binding Events
- Message and Entry
- Checkbutton, Radiobutton, and Scale
- Running GUI Code Three Ways
- Images
- Viewing and Processing Images with PIL
-
9. A tkinter Tour, Part 2
- “On Today’s Menu: Spam, Spam, and Spam”
- Menus
- Listboxes and Scrollbars
- Text
- Canvas
- Grids
- Time Tools, Threads, and Animation
- The End of the Tour
-
10. GUI Coding Techniques
- “Building a Better Mousetrap”
- GuiMixin: Common Tool Mixin Classes
- GuiMaker: Automating Menus and Toolbars
- ShellGui: GUIs for Command-Line Tools
- GuiStreams: Redirecting Streams to Widgets
- Reloading Callback Handlers Dynamically
- Wrapping Up Top-Level Window Interfaces
- GUIs, Threads, and Queues
- More Ways to Add GUIs to Non-GUI Code
- The PyDemos and PyGadgets Launchers
-
11. Complete GUI Programs
- “Python, Open Source, and Camaros”
-
PyEdit: A Text Editor Program/Object
- Running PyEdit
- PyEdit Changes in Version 2.0 (Third Edition)
- PyEdit Changes in Version 2.1 (Fourth Edition)
- PyEdit Source Code
- PyPhoto: An Image Viewer and Resizer
- PyView: An Image and Notes Slideshow
- PyDraw: Painting and Moving Graphics
- PyClock: An Analog/Digital Clock Widget
- PyToe: A Tic-Tac-Toe Game Widget
- Where to Go from Here
-
7. Graphical User Interfaces
-
IV. Internet Programming
-
12. Network Scripting
- “Tune In, Log On, and Drop Out”
- Python Internet Development Options
- Plumbing the Internet
- Socket Programming
- Handling Multiple Clients
- Making Sockets Look Like Files and Streams
- A Simple Python File Server
-
13. Client-Side Scripting
- “Socket to Me!”
- FTP: Transferring Files over the Net
- Transferring Files with ftplib
- Transferring Directories with ftplib
- Transferring Directory Trees with ftplib
- Processing Internet Email
- POP: Fetching Email
- SMTP: Sending Email
-
email: Parsing and Composing Mail Content
- Message Objects
- Basic email Package Interfaces in Action
-
Unicode, Internationalization, and the Python 3.1 email
Package
- Parser decoding requirement
- Text payload encodings: Handling mixed type results
- Text payload encodings: Using header information to decode
- Message header encodings: email package support
- Message address header encodings and parsing, and header creation
- Workaround: Message text generation for binary attachment payloads is broken
- Workaround: Message composition for non-ASCII text parts is broken
- Summary: Solutions and workarounds
- A Console-Based Email Client
- The mailtools Utility Package
- NNTP: Accessing Newsgroups
- HTTP: Accessing Websites
- The urllib Package Revisited
- Other Client-Side Scripting Options
-
14. The PyMailGUI Client
- “Use the Source, Luke”
- Major PyMailGUI Changes
-
A PyMailGUI Demo
- Getting Started
- Loading Mail
- Threading Model
- Load Server Interface
- Offline Processing with Save and Open
- Sending Email and Attachments
- Viewing Email and Attachments
- Email Replies and Forwards and Recipient Options
- Deleting Email
- POP Message Numbers and Synchronization
- Handling HTML Content in Email
- Mail Content Internationalization Support
- Alternative Configurations and Accounts
- Multiple Windows and Status Messages
-
PyMailGUI Implementation
- PyMailGUI: The Main Module
- SharedNames: Program-Wide Globals
- ListWindows: Message List Windows
- ViewWindows: Message View Windows
- messagecache: Message Cache Manager
- popuputil: General-Purpose GUI Pop Ups
- wraplines: Line Split Tools
- html2text: Extracting Text from HTML (Prototype, Preview)
- mailconfig: User Configurations
- textConfig: Customizing Pop-Up PyEdit Windows
- PyMailGUIHelp: User Help Text and Display
- altconfigs: Configuring for Multiple Accounts
- Ideas for Improvement
-
15. Server-Side Scripting
- “Oh, What a Tangled Web We Weave”
- What’s a Server-Side CGI Script?
- Running Server-Side Examples
- Climbing the CGI Learning Curve
- Saving State Information in CGI Scripts
- The Hello World Selector
- Refactoring Code for Maintainability
- More on HTML and URL Escapes
- Transferring Files to Clients and Servers
- 16. The PyMailCGI Server
-
12. Network Scripting
-
V. Tools and Techniques
-
17. Databases and Persistence
- “Give Me an Order of Persistence, but Hold the Pickles”
- Persistence Options in Python
- DBM Files
- Pickled Objects
- Shelve Files
- The ZODB Object-Oriented Database
- SQL Database Interfaces
- ORMs: Object Relational Mappers
- PyForm: A Persistent Object Viewer (External)
- 18. Data Structures
- 19. Text and Language
-
20. Python/C Integration
- “I Am Lost at C”
- Extending Python in C: Overview
- A Simple C Extension Module
- The SWIG Integration Code Generator
- Wrapping C Environment Calls
- Wrapping C++ Classes with SWIG
- Other Extending Tools
- Embedding Python in C: Overview
- Basic Embedding Techniques
- Registering Callback Handler Objects
- Using Python Classes in C
- Other Integration Topics
-
17. Databases and Persistence
-
VI. The End
- 21. Conclusion: Python and the Development Cycle
- Index
- About the Author
- Colophon
- Copyright
Product information
- Title: Programming Python, 4th Edition
- Author(s):
- Release date: December 2010
- Publisher(s): O'Reilly Media, Inc.
- ISBN: 9780596158101
You might also like
book
Tiny Python Projects
The projects are tiny, but the rewards are big: each chapter in Tiny Python Projects challenges …
book
Automate the Boring Stuff with Python
Automate the Boring Stuff with Python teaches simple programming skills to automate everyday computer tasks.
book
40 Algorithms Every Programmer Should Know
Learn algorithms for solving classic computer science problems with this concise guide covering everything from fundamental …
video
Python Fundamentals
51+ hours of video instruction. Overview The professional programmer’s Deitel® video guide to Python development with …