By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,963 Members | 1,749 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,963 IT Pros & Developers. It's quick & easy.

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

P: n/a
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()
Jul 18 '05 #1
Share this question for a faster answer!
Share on Google+

This discussion thread is closed

Replies have been disabled for this discussion.