The first line is, as you know, the "bang" line (sometimes called the "shebang" line) and tells the web server where to find the interpreter for the program (nb: always use absolute paths for this). If you are on Windows, you should substitute for this line the following:
#!c:/python25/python.exe
After importing the sys module, we redirect all error output (stderror) to the screen (stdout). In this way, we ensure that every problem that Python hits is reflected in the output.
Next we import cgitb and os. cgitb prettifies and reports any errors that are thrown in execution. As we will be working with operating system variables, we need the os module.
Importing cgitb is not enough. One must remember to enable it -- the next line does this.
Finally, we import a single function, escape from the cgi module. The purpose of this function is to escape characters such as ampersand ('&'), greater than ('>'), and less than ('<') to HTML-safe sequences ('$amp;', '>', '<', respectively).
The four subsequent print statements set the framework for the HTML output. The fifth calls on the version function of the sys module to determine the version of Python being used, the compiler used to create the binary, and on what kind of system it is running.
