CGI Scripts

Thomas A. Bryan tbryan at python.net
Wed Feb 9 22:10:11 EST 2000


Robert Rutkowski wrote:
> 
> Is it possible the server does not have the cgi or string modules installed?
> How would I find out what is there?

Can you get *any* Python cgi program working?

That is, does something like 

#!/usr/contrib/bin/python
print "At least CGI and Python are working."

work?

If that does not work, then you've got a problem with your 
environment/server.  If something like that does work, then you 
can explore what modules are available by doing things like this:

#!/usr/contrib/bin/python

modules_of_interest = ['string', 'cgi', 'math', 'foo']

print "Content-type: text/html"
print
for module_name in modules_of_interest:
    try:
        exec('import %s' % module_name)
        print "I was able to import %s<BR>" % module_name
    except ImportError:
        print "Couldn't import %s<BR>" % module_name

If you're bored, you could iterate through sys.path, attempt to 
import each .py file in each path in sys.path.  On successful import, 
print a nice HTML table of the methods using dir() with associated
doc strings.  For unsuccessful loads, just print the fact that the load 
was unsuccessful.  

for-extra-credit-use-HTMLgen-to-generate-the-HTML-ly yours
---Tom



More information about the Python-list mailing list