[Tutor] (mod_python v. Python) and Apache

Timothy M. Brauch tbrauch@mindless.com
Thu Jun 12 22:02:01 2003


Probably not the best place to discuss this, but I'm hoping someone can
help.

I'm running Apache 2.0.40-11.5 and Python 2.2.1.  I've successfully
installed and configured mod_python.  However, either I was as successful as
I thought, or mod_python isn't what I wanted.

Okay, so with mod_python I can write scripts, and as long as I have my conf
and permissions set correctly, I can do something like
http://domain.com/dir/script1.py/func and it works.  However, I have to
write each function separately and remember func(req...) for each function.
But, I can't get it to work if I do http://domain.com/dir/script1.py unless
I do as follows.

To get it to work if I just invoke the script directly, assuming conf and
permissions are all in order, All I have to do is something like

#!/usr/bin/python
print "Content-type: text/html\n"

#first two lines are very important as is
print "Hello World."
for i in xrange(10):
    print i
print "That's all folks"

And all is right in the world.  Then, script.py will run and output much
like if I had done []$ python script.py, which is what I am much more
accustomed to in Python programming.

Okay, so two questions, which I know is bad to do, but they are kind of
related.

First, is it possible from command line to call a function in a python
script.  Clearly []$ python script.py/func1() doesn't work.  Nor does
anything else I've tried.  I guess I could use sys.argv and an eval of some
sort.  But that doesn't seem right.

Secondly.  Is mod_python necessary for the second method I listed to work?
I never tried before install mod_python.  If not, why should I use
mod_python?