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.

# - - - - -   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.

import time

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

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.

from decimal import Decimal, InvalidOperation

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

from etbuilder import et, E, subElement, addText

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

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.

from singleton import Singleton