[Tutor] CGI HELP

Dipo Elegbede delegbede at dudupay.com
Wed Oct 6 11:25:44 CEST 2010

Hi all,

I wrote this code as an example from a book:

# Program displaying CGI environment variables.

import os
import cgi

def printHeader(title):
print """Content-type: text/html

<?xml version = "1.0" encoding = "UTF-8"?>
"-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns = "http://www.w3.org/1999/xhtml">

<body>""" % title

rowNumber = 0
backgroundColour = "white"

printHeader("Environmental Variables")
print """<table style = "border: 0">"""

# print table of cgi variables and values
for item in os.environ.keys():
rowNumber += 1

if rowNumber % 2 == 0: # even row numbers are white
backgroundColour = "white"
else: # odd row numbers are grey
backgroundColour = "lightgrey"

print """<tr style = "background-color: %s">
<td>%s</td><td>%s</td</tr>""" %(backgroundColour,
cgi.escape(item), cgi.escape(os.environ[item]))
print """</table></body></html>"""

It was supposed to return a list of environmental variables in a given
Sadly only the header displayed.
I have looked through over and over, please what am i doing wrong.
This is from Deitel How to program python, Chapter 6.

thanks and best regards.
Elegbede Muhammed Oladipupo
Mobile Banking Solutions | Transaction Processing | Enterprise Application
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20101006/92da2dde/attachment.html>

More information about the Tutor mailing list