"Beginning Python: Using Python 2.6 and Python 3.1" introduces this open source, portable, interpreted, object-oriented programming language that combines remarkable power with clear syntax. This book enables you to quickly create robust, reliable, and reusable Python applications by teaching the basics so you can quickly develop Web and scientific applications, incorporate databases, and master systems tasks on various operating systems, including Linux, MAC OS, and Windows. You'll get a comprehensive tutorial that guides you from writing simple, basic Python scripts all the way through complex concepts, and also features a reference of the standard modules with examples illustrating how to implement features in the various modules. Plus, the book covers using Python in specific program development domains, such as XML, databases, scientific applications, network programming, and Web development."
Author(s): James Z. Payne
Edition: 1
Year: 2010
Language: English
Pages: 624
Beginning Python: Using Python 2.6 and Python 3.1
About the Author
Credits
Acknowledgments
Contents
Introduction
Who This Book Is For
What This Book Covers
How This Book Is Structured
What You Need to Use This Book
Conventions
Source Code
Errata
p2p.wrox.com
Part I: Dipping Your Toe into Python
Chapter 1: Programming Basics and Strings
How Programming is Different from Using a Computer
The First Steps
Beginning to Use Python—Strings
Putting Two Strings Together
Putting Strings Together in Different Ways
Summary
Exercises
Chapter 2: Numbers and Operators
Different Kinds of Numbers
Program Files
Using Numbers
Summary
Exercises
Chapter 3: Variables—Names for Values
Referring to Data—Using Names for Data
Using More Built-in Types
Other Common Sequence Properties
Summary
Exercises
Part II: Python Language and the Standard Library
Chapter 4: Making Decisions
Comparing Values—Are They the Same?
Doing the Opposite—Not Equal
Comparing Values—Which One Is More?
Reversing True and False
Looking for the Results of More Than One Comparison
Repetition
Handling Errors
Summary
Exercises
Chapter 5: Functions
Putting Your Program into Its Own File
Functions: Grouping Code under a Name
Layers of Functions
Summary
Exercises
Chapter 6: Classes and Objects
Thinking About Programming
Defining a Class
Summary
Exercises
Chapter 7: Organizing Programs
Modules
Packages
Modules and Packages
Basics of Testing Your Modules and Packages
Summary
Exercises
Chapter 8: Files and Directories
File Objects
Paths and Directories
Exceptions in os
Summary
Exercises
Chapter 9: Other Features of the Language
Lambda and Filter: Short Anonymous Functions
Map: Short-Circuiting Loops
Decisions within Lists—List Comprehension
Generating Iterators for Loops
Special String Substitution Using Dictionaries
Featured Modules
Summary
Exercises
Chapter 10: Building a Module
Exploring Modules
Creating Modules and Packages
Working with Classes
Finishing Your Modules
Creating a Whole Module
Installing Your Modules
Summary
Exercises
Chapter 11: Text Processing
Why Text Processing Is So Useful
Navigating the File System with the os Module
Working with Regular Expressions and the re Module
Summary
Exercises
Part III: Putting Python to Work
Chapter 12: Testing
Assertions
Test Cases and Test Suites
Test Fixtures
Putting It All Together with Extreme Programming
Formal Testing in the Software Life Cycle
Summary
Chapter 13: Writing a GUI with Python
GUI Programming Toolkits for Python
Tkinter Introduction
Creating GUI Widgets with Tkinter
Summary
Exercises
Chapter 14: Accessing Databases
Working with DBM Persistent Dictionaries
Working with Relational Databases
Using the Python Database APIs
Summary
Exercises
Chapter 15: Using Python for XML
What Is XML?
What Is a Schema/DTD?
Document Type Definitions
Schemas
XPath
HTML as a Subset of XML
XML Libraries Available for Python
What Is SAX?
Why Use SAX or DOM
SAX and DOM Parsers Available for Python
Intro to XSLT
What Is lxml?
Element Classes
Parsing with lxml
Summary
Exercises
Chapter 16: Network Programming
Understanding Protocols
Sending Internet E-mail
Retrieving Internet E-mail
Socket Programming
Other Topics
Summary
Exercises
Chapter 17: Extension Programming with C
Extension Module Outline
Building and Installing Extension Modules
Passing Parameters from Python to C
Returning Values from C to Python
The LAME Project
The LAME Extension Module
Using Python Objects from C Code
Summary
Exercises
Chapter 18: Numerical Programming
Numbers in Python
Mathematics
Complex Numbers
Arrays
Summary
Exercises
Chapter 19: An Introduction to Django
What Are Frameworks and Why Would I Use One?
Other Features of Web Frameworks
Django—How It All Began
Understanding Django’s Architecture
Working with Templates
Using Templates and Views
Creating a Model: Creating an Application
Summary
Exercises
Chapter 20: Web Applications and Web Services
REST: The Architecture of the Web
HTTP: Real-World REST
CGI: Turning Scripts into Web Applications
HTML Forms’ Limited Vocabulary
Safety When Accessing Form Values
Building a Wiki
Web Services
REST Web Services
XML-RPC
SOAP
Documenting Your Web Service API
Choosing a Web Service Standard
Web Service Etiquette
Summary
Exercises
Chapter 21: Integrating Java with Python
Scripting within Java Applications
Comparing Python Implementations
Installing Jython
Running Jython
Running Jython on Your Own
Packaging Jython-Based Applications
Integrating Java and Jython
Testing from Jython
Embedding the Jython Interpreter
Handling Differences between C-Python and Jython
Summary
Exercises
Part IV: Appendices
Appendix A: Answers to the Exercises
Chapter 1
Chapter 2
Chapter 3
Chapter 4
Chapter 5
Chapter 6
Chapter 7
Chapter 8
Chapter 9
Chapter 10
Chapter 11
Chapter 13
Chapter 14
Chapter 15
Chapter 16
Chapter 17
Chapter 18
Chapter 19
Chapter 20
Chapter 21
Appendix B: Online Resources
Software
For More Information
Appendix C: What’s New in Python 3.1
Print Is Now a Function
Certain APIs Return Views and Iterators
Integers
Unicode and 8-bit
Exceptions
Classes
Comparisons, Operators, and Methods
Syntactical Changes
Packages and Modules
Builtins
The 2to3 Tool
Appendix D: Glossary
Index