CGI Scripts

Thomas A. Bryan tbryan at python.net
Fri Feb 18 22:37:36 EST 2000


Will Ware wrote:
> 
> Thomas A. Bryan (tbryan at python.net) wrote:
> > modules_of_interest = ['string', 'cgi', 'math', 'foo']
> > for module_name in modules_of_interest:
> >     try: ....
> >     except ImportError: ....
> 
> I am fooling with a CGI script which does what, to me, looks like
> a totally legitimate import from the directory where it itself is.

You can execute the same import from another script in the same 
directory.

> The directory shows up in sys.path and I can do os.listdir() on it

>From within the CGI script?

[..snip..]

> Are there any deeper or more insight-offering ways to debug
> problems with importing? Is there any sort of verbose debug option
> that spews out messages about exactly how or why the import failed?

python -v gives a bunch of information about what was loaded from where, 
but I don't know whether it provides much extra information about modules 
that it cannot load.  You could als try doing a 

except ImportError, msg: 
  print "I failed to load %s with message %s\n" % (module_name, msg)

to see what's actually failing.  Are you getting a "no module named foo"?

You can also start your script with

import sys
sys.stderr = sys.stdout

so that error messages sent to stderr are routed to the user's screen.

Does that help?



More information about the Python-list mailing list