import of 'string' fails in CGI-BIN script...but works in IDLE

J

John F Dutcher

Having 'cloned' an existing python script that imports 'string' and
uses "string.rstrip()" without incident...
I am at a loss to explain why the new 'cloned' script (brief sample
below) continually errors with:
NameError: global name 'string' is not defined
args = ("global name 'string' is not defined",)

when run from the server CGI-BIN.

If the same script is run in 'IDLE' it
works with no problem. Yet, the "import urllib, string" statement is
clearly
present in the script.

I am running Python 2.3.1 on Win 95, using XITAMI as the server.

Troublesome script follows:

#!c:\Python\python.exe
import cgitb; cgitb.enable()
import traceback, sys, os, cgi
import urllib, string
sys.stderr = sys.stdout
form = cgi.FieldStorage()
def writeHTML(rec):
print "Content-Type: text/html"
print
print '''
<FORM ACTION="/cgi-bin/dietsys7.py" METHOD="POST">
<CENTER>
<B><INPUT TYPE="SUBMIT" VALUE="Click to Apply Changes"></B><br><br>'''
print '''
<TABLE BORDER=1 BGCOLOR="FFFF99">'''
cycle = 1
drptr = 7
for x in range(10):
uvalue = string.rstrip(rec[drptr]) <-----(** failure occurs
here)
if not ((cycle % 2) == 0):
print '''<TR bgcolor="pink"><td>'''
else:
print '''<TR bgcolor="yellow"><td>'''
print '''<INPUT TYPE="text" NAME=''' + '"' + 'doctorcode' +
str(cycle) + '"' + ' ' + '''size="36" maxlength="1" value=''' + '"' +
uvalue + '"' + ' ' + '''>'''
print '''<td><b>Doctor Color Code</B></td></tr>'''
cycle = cycle + 1
drptr = drptr + 1
print '''</table></FORM></FONT></BODY></HTML>'''
fileName = os.path. join("c:", "/xitami", "cgi-bin", "dsysmst.dat")
#print 'Globals: ' + str(globals())
#print 'Locals: ' + str(locals())
f = open(fileName, 'rb')
f.seek(-2690,2)
recd = f.read(2690)
if recd[3:7] == '0000':
f.close()
writeHTML(recd)
sys.exit()
else:
print "Did not get utility record"
f.close()
sys.exit()
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top