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.
#!/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.
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.
import lxml.etree as et