Components, Modules and Packages
Delivering Components as Modules and Packages
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
.
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.