Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > import of 'string' fails in CGI-BIN script...but works in IDLE

Reply
Thread Tools

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

 
 
John F Dutcher
Guest
Posts: n/a
 
      12-02-2003
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()
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Import - interpreter works but .py import does not John Boy Python 1 03-10-2008 04:07 AM
When I turn on my PC, it works, works, works. Problem! Fogar Computer Information 1 01-17-2006 12:57 AM
SWIG/IDLE/Python: F5 SHIP.py works but "import SHIP" gives "ImportError: dynamic module does not define init function (initSHIP)" Bill Davy Python 0 05-12-2005 08:48 AM
After rebooting my PC works, works, works! Antivirus problem? Adriano Computer Information 1 12-15-2003 05:30 AM
idle import problem Matthew Wilson Python 0 09-23-2003 04:43 PM



Advertisments