The basic Python language is rich with features. These include several sophisticated built-in data types (Part II, “Data Structures”), numerous basic statments (Part I, “Language Basics”), a variety of common arithmetic operators and a library of built-in functions. In order to keep the basic Python kernel small, relatively feature features are built-in. A small kernel means that Python interpreters can be provided in a variety of software application, extending functionality of the application without bloating due to a large and complex command language.
The more powerful and sophisticated features of Python are separated into extension modules. There are several advantages to this. First, it allows each program to load only the relevant modules, speeding start-up. Second, it allows additional modules to be added easily. Third, it allows a module to be replaced, allowing you to choose among competing solutions to a problem.
The second point above, easily adding modules, is something that needs to be emphasized. In the Python community, this is called the batteries included principle. The ideal is to make Python directly applicable to just about any practical problem you may have.
Some modules have already been covered in other chapters. In the section called “The math Module” we covered math and
random modules. In Chapter 12, Strings we covered the string
module.
Overview of this part. This part will cover selected features of a few modules. The objective is to introduce some of the power of key Python modules and show how the modules are used to support software development. This isn't a reference, or even a complete guide to these modules. The standard Python Library documentation and other books describe all available modules in detail. Remember that Python is an open-source project: in some cases, you'll have to read the module's source to see what it really does and how it works.
This part provides a general overview of how to create Python modules in Chapter 28, Modules. It also covers how to create packages in Chapter 30, The Python Library. An overview of the Python library is the focus of Chapter 30, The Python Library.
Module Details. We cover several essential modules in some detail.
Chapter 31, Complex Strings: the re Module covers
regular expressions, which you can use to do
string matching and parsing.
Chapter 32, Dates and Times: the time and
datetime Modules covers how to handle
the vagaries of our calendar with the time and
datetime modules.
We'll cover the basics of file handling in Chapter 33, File Handling Modules; this includes modules like:
sys, glob,
fnmatch, fileinput,
os, os.path,
tempfile, and
shutil.
We'll also look at modules for reading and writing files in various formats in Chapter 34, File Formats: CSV, Tab, XML, Logs and Others.
the section called “Comma-Separated Values: The csv
Module” will cover Comma
Separated Values (CSV) files.
Tab-delimited files, however, are a simpler problem, and don't require a separate module.
the section called “Property Files and Configuration (or.INI)
Files: The ConfigParser Module” will cover
parsing Configuration files, sometimes called
.INI files. An .INI file
is not the best way to handle configurations, but this technique
is common enough that we need to show it.
the section called “Fixed Format Files, A COBOL Legacy: The
codecs Module” will cover ways
to handle COBOL files which are in a "fixed length" format, using
EBCDIC data instead of the more common ASCII or Unicode.
the section called “XML Files: The
xml.minidom and xml.sax
Modules” will cover the
techniques for parsing XML files.
Programs -- The Ultimate Modules. In a sense a top-level program is a module that does something useful. It's important understand "programs" as being reusable modules. Eventually most really useful programs get rewritten and merged into larger, more sophisticated programs.
In Chapter 35, Programs: Standing Alone this part covers modules
essential for creating polished, complete stand-alone programs. This
includes the getopt and
optparse modules.
The final chapter covers integration among programs using the client-server programming model. This includes a number of modules that are essential for creating networked programs.
We can use the HTTP protocol with a number of modules covered in the section called “Web Servers and the HTTP protocol”.
We can use the XML-RPC standards to create or use web services.
This is covered in the section called “Web Services: The xmlrpclib Module”.
Using the section called “Mid-Level Protocols: The urllib2
Module”, we can leverage a
number of protocols to read a file located anywhere on the World-Wide
Web via their Uniform Resource Locator (URL).
If none of these protocols are suitable, we can invent our own, using the low-level socket module, covered in the section called “Socket Programming”.
Table of Contents
re Moduletime and
datetime Modules