Next / Previous / Contents / TCC Help System / NM Tech homepage

5.2. Prologue

We'll start off with the usual “pound-bang line” that makes the script self-executing, followed by a comment that points to this documentation.

anyform.cgi
#!/usr/bin/env python
#================================================================
# anyform.cgi:  General-purpose Web form handler script.
#   For documentation, see:
#     http://www.nmt.edu/tcc/help/pubs/pycgi/
#----------------------------------------------------------------

We'll use the standard cgi and urllib modules described above. We also need the sys module to access the standard output stream, sys.stdout.

anyform.cgi
import cgi, urllib, sys

The author considers it a rather sloppy and dangerous practice to generate HTML using ordinary print statements. Hence, this example uses the ElementTree module, a good choice for generating XHTML, and a component of the standard Python library. We'll refer to it internally as et. For full documentation on this module, see the author's Python XML processing with lxml.

anyform.cgi
import lxml.etree as et