Beginning Python

Using Python 2.6 and Python 3.1

James Payne

Publisher: Wrox, 2010, 588 pages

ISBN: 978-0-470-41463-7

Keywords: Python

Last modified: Feb. 28, 2013, 10:43 p.m.

Create a robust, reliable, and reusable Python application

As an open source, object-oriented programming language, Python is easy to understand, extendable, and user-friendly. This book covers every aspect of Python so that you can get started writing your own programs with Python today. Author James Payne begins with the most basic concepts of the Python language—placing a special focus on the 2.6 and 3.1 versions—and he offers an in-depth look at existing Python programs so you can learn by example. Topics progress from strings, lists, and dictionaries to classes, objects, and modules. With this book, you will learn how to quickly and confidently create a robust, reliable, and reusable Python application.

Beginning Python:

  • Introduces the concepts of variables for storing and manipulating data
  • Examines files and input/output for reading or writing data
  • Reviews examples of often-overlooked features of Python
  • Delves into writing tests for modules and programs
  • Addresses programming with a graphical user interface in Python
  • Places special focus on XML, HTML, XSL, and related technologies
  • Explains how to extend Python
  • Shares numerical programming techniques
  • Offers an inside look at Jython, a version of Python written in Java
  • Part I: Dipping Your Toe into Python
    • Chapter 1: Programming Basics and Strings
      • How Programming is Different from Using a Computer
        • Programming is Consistency
        • Programming is Control
        • Programming Copes with Change
        • What All That Means Together
      • The First Steps
        • Installing Python 3.1 on Non-Windows Systems
        • Using the Python Shell
      • Beginning to Use Python — Strings
        • What is a String?
        • Why the Quotes?
        • Why Three Types of Quotes?
        • Using the print() Function
        • Understanding Different Quotes
      • Putting Two Strings Together
        • Joining Strings with the Print() Function
      • Putting Strings Together in Different Ways
      • Summary
      • Exercises
    • Chapter 2: Numbers and Operators
      • Different Kinds of Numbers
        • Numbers in Python
      • Program Files
        • Using the Different Types
        • Basic Math
        • Some Surprises
      • Using Numbers
        • Order of Evaluation
        • Number Formats
        • Mistakes Will Happen
        • Some Unusual Cases
      • Summary
      • Exercises
    • Chapter 3: Variables — Names for Values
      • Referring to Data — Using Names for Data
        • Changing Data Through Names
        • Copying Data
        • Names You Can't Use and Some Rules
      • Using More Built-in Types
        • Tuples — Unchanging Sequences of Data
        • Lists — Changeable Sequences of Data
        • Dictionaries — Groupings of Data Indexed by Name
        • Treating a String Like a List
        • Special Types
      • Other Common Sequence Properties
        • Referencing the Last Elements
        • Ranges of Sequences
        • Growing Lists by Appending Sequences
        • Using Lists to Temporarily Store Data
        • Working with Sets
      • Summary
      • Exercises
  • Part II: Python Language and teh Standard Library
    • Chapter 4: Making Decisions
      • Comparing Values — Are They the Same?
      • Doing the Opposite — Not Equal
      • Comparing Values — Which One Is More?
        • More Than or Equal, Less Than or Equal
      • Reversing True and False
      • Looking for the Results of More Than One Comparison
        • How to Get Decisions Made
      • Repetition
        • How to Do Something — Again and Again
        • Stopping the Repetition
      • Handling Errors
        • Trying Things Out
      • Summary
      • Exercises
    • Chapter 5: Functions
      • Putting Your Program into Its Own File
      • Functions: Grouping Code under a Name
        • Choosing a Name
        • Describing a Function in the Function
        • The Same Name in Two DIfferent Places
        • Making Notes to Yourself
        • Asking a Function to Use a Value You Provide
        • Checking Your Parameters
        • Setting a Defaulty Value for a Parameter — Just in  Case
        • Calling Functions from within Other Functions
        • Functions Inside of Functions
        • Flagging an Error on Your Own terms
      • Layers of Functions
        • How to Read Deeper Errors
      • Summary
      • Exercises
    • Chapter 6: Classes and Objects
      • Thinking About Programming
        • What is an Object?
        • Objects You Already Know
        • Looking Ahead: How You Want to Use Objects
      • Defining a Class
        • How Code Can Be Made into an Object
        • Objects and Their Scope
      • Summary
      • Exercises
    • Chapter 7: Organizing Programs
      • Modules
        • Importing a Module So That You Can Use It
        • Making a Module from Pre-existing Code
        • Using Modules — Starting with the Command Line
        • Changing How Import Works — Bringing in More
      • Packages
      • Modules and Packages
        • Bringing Everything into the Current Scope
        • Re-importing Modules and Packages
      • Basics of Testing Your Modules and Packages
      • Summary
      • Exercises
    • Chapter 8: Files and Directories
      • File Objects
        • Writing Text Files
        • Appending Text to a File
        • Reading Text Files
        • File Exceptions
      • Paths and Directories
      • Exceptions in os
        • Paths
        • Directory Contents
        • Obtaining Information about Files
        • Renaming, Moving, Copying, and Removing Files
        • Example: Rotating Files
        • Creating and Removing Directories
        • Globbing
      • 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
        • Getopt — Getting Options from the Command Line
        • Using More Than One Process
        • Threads — Doing Many Things in the Same Process
      • Summary
      • Exercises
    • Chapter 10: Building a Module
      • Exploring Modules
        • Importing Modules
        • Finding Modules
        • Digging through Modules
      • Creating Modules and Packages
      • Working with Classes
        • Defining Object-Oriented Programming
        • Creating Classes
        • Extending Existing Classes
      • Finishing Your Modules
        • Defining Module-Specific Errors
        • Choosing What to Export
        • Documenting Your Modules
        • Testing Your Module
        • Running a Module as a Program
      • Creating a Whole Module
      • Installing Your Modules
      • Summary
      • Exercises
    • Chapter 11: Text Processing
      • Why Text Processing Is So Useful
        • Searching for Files
        • Clipping Logs
        • Sifting through Mail
      • 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
        • Implementing a Search Utility in Python
        • A More Powerful Python Search
      • 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
        • Resizing the Widget
        • Configuring Widget Options
        • Putting the Widgets to Work
        • Creating Layouts
        • Packing Order
        • Controlling Widget Appearances
        • Radio Butgtons and Checkboxes
        • Dialog Boxes
        • Other Widget Types
      • Summary
      • Exercises
    • Chapter 14: Accessing Databases
      • Working with DBM Persistent Dictionaries
        • Choosing a DBM Module
        • Creating Persistent Dictionaries
        • Accessing Persistent Dictionaries
        • Deciding When to Use DBM and When to Use a Relational Database
      • Working with Relational Databases
        • Writing SQL Statements
        • Defining Tables
        • Setting up a Database
      • Using the Python Database APIs
        • Downloading Modules
        • Creating Connections
        • Working with Cursors
        • Working with Transactions and Committing the Results
        • Examining Module Capabilities and Metadata
        • Handling Errors
      • Summary
      • Exercises
    • Chapter 15: Using Python for XML
      • What Is XML?
        • A Hierarchical Markup Language
        • A Family of Standards
      • What Is a Schema/ DTD?
        • What Are Document Models For?
        • Do you Need One?
      • Document Type Definitions
        • An Example DTD
        • DTDs Aren't Exactly XML
        • Limitations of DTDs
      • Schemas
        • An Example Schema
        • Schemas Are Pure XML
        • Schemas Are Hierarchical
        • Other Advantages of Schemas
      • XPath
      • HTML as a Subset of XML
        • The HTML DTDs
        • HTMLParser
      • XML Libraries Available for Python
      • What Is SAX?
        • Stream-based
        • Event-driven
        • What Is DOM?
        • In-memory Access
      • Why Use SAX or DOM
        • Capability Trade-Offs
        • Memory Considerations
        • Speed Considerations
      • SAX and DOM Parsers Available for Python
        • xml.sax
        • xml.dom.minidom
      • Intro to XSLT
        • XSLT is XML
        • Transformation and Formatting Language
        • Functional, Template-Driven
      • What Is lxml?
      • Element Classes
        • Adding Text to Elements
      • Parsing with lxml
        • Parsing Files
      • Summary
      • Exercises
    • Chapter 16: Network Programming
      • Understanding Protocols
        • Comparing Protocols and Programming Languages
        • The Internet Protocol Stack
        • A Little Bit About the Internet Protocol
      • Sending Internet E-mail
        • The E-mail File Format
        • MIME Messages
        • Sending Mail with SMTP and smtplib
      • Retrieving Internet E-mail
        • Parsing a Local Mail Spool with mailbox
        • Fetching Mail from a POP3 Server with poplib
        • Fetching Mail from an IMAP Server with imaplib
        • Secure POP3 and IMAP
        • Webmail Applications Are Not E-mail Applications
      • Socket Programming
        • Introduction to Sockets
        • Binding to an External Hostname
        • The Mirror Server
        • The Mirror Client
        • SocketServer
        • Multithreaded Servers
        • The Python Chat Server
        • Design of the Python Chat Server
        • The Python Chat Server Protocol
        • The Python Chat Client
        • Single-Threaded Multitasking with select
      • Other Topics
        • Miscellaneous Considerations for Protocol Design
        • The Peer-to-Peer Architecture
      • 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
        • Integers
        • Long Integers
        • Floating-point Numbers
        • Formatting Numbers
        • Characters as Numbers
      • Mathematics
        • Arithmetic
        • Built-in Math Functions
      • Complex Numbers
      • Arrays
        • The array Module
      • 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
        • Installing Django
      • Understanding Django's Architecture
        • Initial Project Setup
        • Creating a View
      • Working with Templates
      • Using Templates and Views
        • Models
        • Creating a Model: First Steps — Configure the Database Settings
      • Creating a Model: Creating an Application
        • Working with Models: Installation
      • Summary
      • Exercises
    • Chapter 20: Web Applications and Web Services
      • REST: The Architecture of the Web
        • Characteristics of REST
        • REST Operations
      • HTTP: Real-World REST
        • The Visible Web Server
        • The HTTP Request
        • The HTTP Response
      • CGI: Turning Scripts Into Web Applications
        • The Web Server Makes a Deal with the CGI Script
        • CGI's Special Environment Variables
        • Accepting User Input through HTML Forms
      • HTML Forms' Limited Vocabulary
        • The cgi Module: Parsing HTML Forms
      • Safety When Accessing Form Values
      • Building a Wiki
        • The BittyWiki Core Library
        • The BittyWiki Web Interface
      • Web Services
        • How Web Services Work
      • REST Web Services
        • REST Quick Start: Finding Bargains on Amazon.com
        • Introducing WishListBargainFinder
        • Giving BittyWiki a REST API
        • Wiki Search-and-Replace Using the REST Web Service
      • XML-RPC
        • The XML-RPC Request
        • The XML-RPC Response
        • If Something Goes Wrong
        • Exposing the BittyWiki API through XML-RPC
        • Wiki Search-and-Replace Using the XML-RPC Web Service
      • SOAP
        • SOAP Quick Start
        • The SOAP Request
        • The SOAP Response
        • If Something Goes Wrong
        • Exposing a SOAP Interface to BittyWiki
        • Wiki Search-and-Replace Using the SOAP Web Service
      • Documenting Your Web Service API
        • Human-Readable API Documentation
        • The XML-RPC Introspection API
        • WSDL
      • Choosing a Web Service Standard
      • Web Service Etiquette
        • For Consumers of Web Services
        • For Producers of Web Services
        • Using Web Applications as Web Services
      • Summary
      • Exercises
    • Chapter 21: Integrating Java with Python
      • Scripting within Java Applications
      • Comparing Python Implementations
      • Installing Jython
      • Running Jython
        • Running Jython Interactively
        • Running Jython Scripts
        • Controlling the Jython Script
        • Making Executable Commands
      • Running Jython on Your Own
      • Packaging Jython-Based Applications
      • Integrating Java and Jython
        • Using Java Classes in Jython
        • Accessing Databases from Jython
        • Writing Java EE Servlets in Jython
        • Choosing Tools for Jython
      • Testing from Jython
      • Embedding the Jython Interpreter
        • Calling Jython Scripts from Java
      • Handling Differences between C-Python and Jython
      • Summary
      • Exercises
  • Part IV: Appendices
    • Appendix A: Answers to the Exercises
    • Appendix B: Online Resources
    • Appendix C: What's New in Python 3.1
    • Appendix D: Glossary

Reviews

Beginning Python

Reviewed by Roland Buresund

OK ***** (5 out of 10)

Last modified: Feb. 28, 2013, 10:43 p.m.

This is a very strange book. It manages to explain a lot of the web-world (SOAP, XML-RPC, REST), the application architectures (MTV, MVC, etc) and goes into concepts like list comprehension etc. But manages to totally loose sight of generators, with… and other modern concepts of Python.

I bought it to have a reference book for the differences between Python 2.x and 3.x, which it fails miserably. I then reconsidered and was thinking to use it as a teaching tools for new Python programmers, but it fails again in this respect. Then I decided to use the excellent last half of the book that discusses networks, web-architecture, XML, etc as an easy to use reference for explaining these concepts, which it succeeds in very well.

Overall, it can't get more than a OK rating, as it fails on so many points, but still has some value.

Comments

There are currently no comments

New Comment

required

required (not published)

optional

required

captcha

required