[Tutor] (mod_python v. Python) and Apache
Magnus Lyckå
magnus@thinkware.se
Fri Jun 13 15:19:01 2003
At 22:01 2003-06-12 -0400, Timothy M. Brauch wrote:
>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.
What's a []$ script? I know what a CGI script is...
>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.
You can allways provide the function name as a command line argument,
or rather as a parameter in GET or POST. Then you can have something
like that:
command = <the parameter string that you got as input>
def x():
...
def y():
...
if command in ['x', 'y']:
globals()[command]
else:
error_handling()
>If not, why should I use mod_python?
The main reason I see for using mod_python is to improve performance.
With CGI scripts, the python interpreter and all the modules you import
are loaded from disk each time you call a script. With mod_python it's
staying in memory between calls. For Python CGI scripts, this startup
time is very often the main issue limiting performance.
--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The Agile Programming Language