作者:empty 页数:1628 出版社:empty |
How do you apply Python once youve mastered its fundamentals tThis book provides in-depth tutorials on the language's primaryapplication domains—system administration.GUIs, and the Web—and explores its use in databases, networking, front-end scriptinglayers, text processing.and more.By focusing on commonlyused tools and libraries, you'll gain an in-depth understanding ofPython's roles in practical real-world programming.Youll lear language syntax and programming techniques in aclear and concise manner, with lots of examples that illustrateboth come ct usage and common idioms.Completely updated forversion 3.x, Programming Pyi bon also delves into the languageas a software development tool, with many code examples scaledspecifc ally for that purpose.
this book Det also n last page.data representation, object-oriented programming,object persistence, GUl s, and website basics.m System programming:Explore system interface tools andtechniques for command-line scripting, processing filesand folders, running programs in parallel, and more.GUI programming:Learn to use Pythons tkinter widgetlibrary to build complete user interfaces.Internetprogramming:Accessclient-sidenetworkprotocols and email tools, use CGl scripts, and learnwebsite implementation techniques.More ways to apply Python:Implement datastructures,parse text-based information, interface with databases,and extend and embed Python,Previous programming experiences recommended.
Publ hed by OReilly Media, In e, , 1005 Gravenstein Highway North, Sebastopol, CA 95472O'Relly books maybe purchased for educational, business, or sales promotional use.On lc editionsarca lsn available form est titles(http://mysafaribooksanlinc.com) .Form or c information, contact oarcopoaensubanalslsde parent(HoD 998-993BorEwpuurorlyaomProduction Editor:Teresa ElseyCwr Des ne:Kaen Mont meryProofreader:Teresa ElseyPnt ing History:First Edi ion.March 2001:Second Edition,August 2006:Th id Edt onDecember 2010:Fourth Edition.Nur shell Handbook, the Nuts hel Handbook logo, and the OR illy logo are registered ta de marks ofO'Relly Med uu, Inc.Program mng Python, the image of an African tock python, and related trade dressarc trademarks of O'Reilly Media, Inc.Many of the designations used by manufacturers and sellers to distinguish their products are claimed astrade marles.Where t has e designations appear in this book, and OReilly Media, Inc., was aware of atrademark dl aim, the designations have been pnntedincapsorinialcaps.Whlceveypeccautin has been taken in the prep a at in ef this book.t be pubs her and auhor ass menote sponsibility for errors or omissions, or for damages resulting trom the use of the information con-
Part I.The Beginning
1.A Sneak Preview.
Part II.System Programming
Program mng Python:The Short Story
The Task
Step l:Representing Records
Using Lists
Using Dictionaries
Step2:5toringRecordsPersistently
Using Format red Files
Using Pickle Files
Using Per-Record Pickle Files
Using Shelves
Step3:SteppingUptoOOP
Using Classes
Adding Behavior
Adding Inheritance
Refactoring Code
Adding Persistence
Other Database Options
Step4:AddingConsoleInteraction
A Console Shelve Interface
Step5:AddingaGUI
GUI Basics
Using OOP for GUl s
Getting Input from a User
A GUI Shelve Interface
Step6:AddingaWebInterface
CGI Basics
Running a WebServer
Using Query Strings and urllib
Formatting Reply Text
A Web-Based Shelve Interface
The End of the Demo
2.System Tools.
The os.path to Knowledge
Why Python Here?
The Next Five Chapters
System Scripting Overview
Python System Modules
Module Documentation Sources
Paging Documentation Strings
A Custom Paging Seri pt
String Method Basics
CWD, Files, and Import Paths
CWD and Command Lines
Other String Concepts in Python 3.X Unicode and bytes
File Operation Basics
Using Programs in Two Ways
Python Library Manuals
Commercially Published References
Introducing the sys Module
Platforms and Versions
The Module Search Path
The Loaded Modules Table
Exception Details
Other sys Module Exports
Introducing the os Module
Tools in the os Module
Administrative Tools
Porr ability Constants
Common os.path Tools
Running Shell Commands from Scripts
Other os Module Exports
3.5cript Execution Context.
ral keto Have an Argu men, Please
Current Working Directory
Parsing Command-Line Arguments
Shell Environment Van ables
Fetching Shell Variables
Changing Shell Variables
The fork/exec Combination
The_thread Module
The threading Module
The queue Module
Preview:GUIs and Threads
More on the Global Interpreter Lock
sys Module Exits
os Module Exits
Shell Command Exit Status Codes
Process Exit Status and Shared State
Thread Exits and Shared State
Anonymous Pipes
Named Pipes(Fifos)
Sockers:A First Look
Signals
Why multiprocessing?
The Basics:Processes and Locks
Scanning the Standard Library Directory
Scanning the Standard Library Tree
Scanning the Module Search Path
Scanning the Entire Machine
Printing Unicode Filenames
Splitting Files Portably
Joining Files Portably
Usage Va nations
Page Template File
Page Generator Script
Running the Test Driver
Finding Directory Differences
Finding Tree Differences
Running theSe rip t
Verifying Backups
Reporting Differences and Other ldc as
Shell Van able Fine Points:Parents, putenv, and getenv
Standard Streams
Redirecting Streams to Files and Programs
Redirected Streams and User Interaction
Redirecting Streams to Python Objects
The io.String lOan dio.Bytes lO Utility Classes
Capturing the stderr Stream
Redirection Syntax in Print Calls
4.File and Directory Tools.
A Quick Game of“Find the Biggest Python File”
Spl ict ing and Joining Fles
Other Redirection Options:os.popen and subprocess Re vii ted
Erase Your HardDrive in Five Easy Steps l
File Tools
The File Object Model in Python 3.X
Using Built-in File Objects
Binary and Text Files
Lower-Level File Tools in the os Module
File Scanners
Directory Tools
Walking One Directory
Walking Directory Trees
Handling Unicode Filenames in 3.X:listdir, walk, glob
5.Parallel System Tools.
Teng the Monkeys What to Do
For king Processes
Threads
Program Exits
Interprocess Communication
The multiprocessing Module
Table of Con tens|wi
IPC Tools:Pipes, Shared Memory, and Queues
Starting Independent Programs
And Much More
Why multiprocessing?The Conclusion
Other Ways to Start Programs
The os.spawn Calls
The os.start file call on Windows
A Portable Program-Launch Framework
Other System Tools Coverage
6.Complete System Programs.
“The Grep s of Wrath
Generating Red rection WebPages
A Regression Test Script
Copying Directory Trees
Comparing Directory Trees
Searching Directory Trees
Grep sand Globs and Finds
Rolling Your Own find Module
Cleaning Up Bytecode Files
A Python Tree Searcher
Editing Files in Directory Trees(Visitor)
Global Replacements in Directory Trees(Visitor}
Counting SourceCode Lines(Visitor)
Recoding Copies with Classes(Visitor)
Other Visitor Examples(Exte mal)
Playing Media Files
The Python webbrowser Module
The Python mimetypes Module
Running theSe npt
Automated Program Launchers(Exte mal)
Heres Looking ar You, Kd
GUI Programming Topics
Running the Examples
Python GUI Development Options
tkinter Overview
tkinter Pragmatics
tkinter Documentation
tkinter Extensions
tkinter Structure
Cl bing the GUl Learning Curve
“HelloWorld in Four Lines for Less)
tkinter Coding Basics
Making Widgets
Geometry Managers
Running GUI Programs
tkinter Coding Alternatives
Widget Resizing Basics
Configuring Widget Options and Window Titles
One More for Old Times'Sake
Packing Widgets Without Saving Them
Adding Buttons and Callbacks
Widger Resizing Revisited:Expansion
Adding User-Defined Callback Handlers
Lambda Callback Handlers
Deferring Calls with Lambdas and Object References
Callback Scope Issues
Bound Method Callback Handlers
Callable Class Object Callback Handlers
Other tkinter Callback Protocols
Binding Events
Adding Multiple Widger s
Widger Resizing Revisited:Clipping
Attaching Widgets t oF rates
layout:Packing Order and Side Attachments
The Packers Expand and Fll Revisited
Using Anchor to Position Instead of Stretch
Customizing Widgets with Classes
Standardizing Behavior and Appearance
Reusable GUI Components with Classes
Attaching Class Components
Extending Class Components
Standalone Container Classes
The End of the Tutor al
Python/tkinter for Tal/Tk Converts
Widgets and Gad ges and C Us.Oh My l
This Chapter's Topics
Configuring Widger Appearance
Top-Level Windows
Toplevel and Tk Widgets
Top-Level Window Protocols
Dialogs
Standard(Common) Di logs
The Old-Style Dialog Module
Custom Dialogs
Binding Events
Other bind Events
Message and Entry
Message
Entry
Laying Ou