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

Lee Brown administrator at leebrown.org
Tue Sep 13 18:47:13 EDT 2005

No, I won't draw you a picture, but I'll give you a push in the right
direction:  If you were to use

	import mpglobals.py

In any other ordinary python program, in what namespace would you expect to
find the contents of mpglobals?

Best Regards,
Lee E. Brown
(administrator at leebrown.org)

-----Original Message-----
From: mod_python-bounces at modpython.org
[mailto:mod_python-bounces at modpython.org] On Behalf Of
jamestmcneill-python at yahoo.co.uk
Sent: Tuesday, September 13, 2005 10:38 AM
To: mod_python at modpython.org
Subject: [mod_python] PythonImport: Can someone please draw a diagram
forthis idiot?

Good afternoon. I wonder if someone may be able to help me get to the
starting line with mod_python? I'm trying to use PythonImport to create a
database connection which I can use for subsequent requests, and I haven't
been able to figure out how. Here's what I'm putting in httpd.conf: 

PythonInterpreter maininterpreter
PythonImport mpglobals maininterpreter
<Directory "C:\Program Files\Apache Group\Apache2\htdocs\moddy">
    AddHandler mod_python .py
    PythonHandler mptest
    PythonDebug On

mpglobals.py is in the "C:\Program Files\Apache Group\Apache2\htdocs\moddy"
folder, and an entry in c:\python23\mp.pth adds this to sys.path.
mpglobals.py attempts to load a database connection as global:

import kinterbasdb as fbd
con = fbd.connect(dsn='localhost:C:\Program
cur = con.cursor()

Finally, the default python handler mptest.py tries to use the connection:

def handler(req):
    cur.execute('select * from EMPLOYEE order by LAST_NAME')
    . . . .
    return apache.OK

This throws up an error:

  File "C:/Program Files/Apache Group/Apache2/htdocs/moddy/\mptest.py",
line 8, in handler
    cur.execute('select * from EMPLOYEE order by LAST_NAME')
NameError: global name 'cur' is not defined

Am I anywhere near going about this the right way? Can someone please draw
me a diagram?


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

Mod_python mailing list
Mod_python at modpython.org

More information about the Mod_python mailing list