[mod_python] persistent values

Gregory (Grisha) Trubetskoy grisha at modpython.org
Mon Jun 23 21:28:58 EST 2003

I just tried it and it works fine for me. I followed the steps you
outlined with "/home/grisha/www/htdocs" as my current directory, here is
an excerpt from apache config:

LoadModule python_module modules/mod_python.so

<Directory /home/grisha/www/htdocs>
        SetHandler python-program
        PythonHandler blah

And here is /home/grisha/www/htdocs/blah.py:

from mod_python import apache

from pkg import baz

def handler(req):
    return apache.OK

There's got a detail that I'm missing here.


On Mon, 23 Jun 2003, Sean Reifschneider wrote:

> On Mon, Jun 23, 2003 at 06:31:47PM -0400, Gregory (Grisha) Trubetskoy wrote:
> >There isn't anything unusual about the way mod_python imports modules.
> Someone on this list replied to one of my earlier messages and said that
> mod_python hooks into the import mechanism for some reason.
> There definitely are issues related to importing of packages...  From
> mod_python, if I import a package that has a module within it, I can't
> access that name unless the package __init__.py imports that name.  For
> example, the following works from Python:
>    guin:p$ mkdir pkg
>    guin:p$ echo >pkg/__init__.py
>    guin:p$ echo 'foo = "bar"' >pkg/baz.py
>    guin:p$ python -c 'from pkg import baz; print baz.foo'
>    bar
>    guin:p$
> IIRC, in mod_python that would give me an AttributeError on the "from
> pkg import baz", unless I do:
>    echo 'import baz' >pkg/__init__.py
> Of course, this means that my entire package structure must be imported
> through the __init__.py files, even if not all of it is used.  Worse,
> this means that I can't have a module which imports another module, that
> imports the first module...
> >PythonAutoReload can yeld strange results after a lot of changes and a lot
> >of reloading, but that's not unusual during development. A cleanly started
> >Apache should (and does for me at least) behave 100% predictably.
> That's not been my experience, where "predictably" is defined as
> "behaving as I expect Python code to".  I mean, it's predictable in it's
> unpredictability.  ;-)
> Sean
> --
>  What we see depends on mainly what we look for.
>                  -- John Lubbock
> Sean Reifschneider, Member of Technical Staff <jafo at tummy.com>
> tummy.com, ltd. - Linux Consulting since 1995.  Qmail, Python, SysAdmin

More information about the Mod_python mailing list