Next / Previous / Contents / Shipman's homepage

7. Imports

We need the standard sys module for standard streams and the command line; os for operating system functions; and the standard stat module for extracting file timestamps.

listext2
# - - - - -   I m p o r t s

from __future__ import print_function
import sys, os, stat

For formatting timestamps, we use the standard Python time module library. The datetime module is much more full-featured, especially regarding time zones, but we just want the local time.

listext2
import time

Command line processing is handled by the standard Python argparse module. (Requires Python 2.6 or later.)

listext2
import argparse

Some units are handled as fixed-point quantities. These use Python's standard decimal module. InvalidOperation is the exception raised when a conversion to decimal fails.

listext2
from decimal import Decimal, InvalidOperation

Basic XML generation is handled by the etbuilder module from Python XML processing with lxml.

listext2
from etbuilder import et, E, subElement, addText

For functions specific to building XSL-FO files, we use the module from fohelpers.py: XSL-FO helper functions for Python. Because these functions are used so many times, we import the module as h (for helpers).

listext2
import fohelpers as h

Section 18, “class Args: Command line arguments” uses the Singleton design pattern. We import the singleton module from Scanning objects for Python: Scan and Log.

listext2
from singleton import Singleton