[mod_python] PythonImport: Can someone please draw a diagram for this idiot?

jamestmcneill-python at yahoo.co.uk jamestmcneill-python at yahoo.co.uk
Thu Sep 15 08:28:14 EDT 2005


Jim,

Thank you, I'm not sure exactly what is different about your example but
I've just tested it and it works fine. Just so the next idiot that comes
along has a little easier time of it than me, here's a diagram of how to
prove PythonImport works under XP:

1) add the location of your import code to the PythonPath, by placing a
file called <something>.pth in your python folder, e.g. 
c:\python23\mpg.pth. Contents for instance:
C:\mod_python

2) put your import code into the folder you have specified above, by
creating a file c:\mod_python\mpg.py:
# mpg.py
import time
f = open(r'C:\mod_python\mpgtest.txt', 'w')
f.write(str(time.time()))
f.close()
foo = 'testing'

3) put a similar section to this in the main part of your Apache config
file (not within any directory or other section, it has to be in the main
part):
PythonInterpreter mpginterpreter
PythonImport mpg mpginterpreter
<Directory "C:\Program Files\Apache Group\Apache2\htdocs\moddy">
    AddHandler mod_python .py
    PythonHandler mpgtest
    PythonDebug On
</Directory>

4) finally, in the directory specified in your Apache config file add the
request handler code:
""" mpgtest.py"""
from mod_python import apache
import sys
mpglobal = sys.modules['mpg']
def handler(req):
    req.write('Hello world\n')
    req.write(mpglobal.foo)
    return apache.OK


Browse to http://localhost/moddy/mince.py. You should now find the
compiled mpg.pyc in your c:\mod_python folder, also the test file
mpgtest.txt written at import time.

Apologies to those of you for whom this kid's stuff must be like watching
paint dry. Any mistakes are mine.

Regards,
Jim McNeill

--- Jim Gallacher  wrote:

> Jorey Bump wrote:
> > Jim Gallacher wrote:
> > 
> >> In answer to my own in question, PythonImport does work and there is 
> >> no bug. Re-reading the docs reveals this small detail which I and 
> >> others may have overlooked - the context for the directive. 
> >> PythonImport only works in the server config context. 


++++++++++++++++++++++++++++++++++++++++++++++++++
+   If you've got a good excuse - don't use it   +
++++++++++++++++++++++++++++++++++++++++++++++++++)



More information about the Mod_python mailing list