[mod_python] psp_site example doesn't work

Jorey Bump list at joreybump.com
Mon Jan 24 14:56:23 EST 2005


Daniel Popowich wrote:

> Thank you Jorey for your detailed email, but I have to disagree with
> you when you wrote:
> 
>     This is consistent with normal Python behaviour, where an
>     interpreter loads modules from the current directory or
>     PYTHONPATH. [1]
> 
> I came to mod_python after *many* years of intensive python
> programming and as a newbie to mod_python was caught by this issue for
> days.  The way mod_python imports files all at the same root level is
> very UN-pythonic.  

Yes, I'll concede that. But, mod_python.publisher must remove leading 
path information when the published modules are imported, otherwise 
Python wouldn't import them (unless they happen to be in sys.path). It's 
important to understand that the module in the URL is being imported by 
another module, not run directly by the interpreter, as when you type 
"python app.py" on the command line. It took a while for this to sink in 
completely, myself.

There is no mechanism in Python to import a module by file path, so it's 
consistent, but confusing. The alternative would have been to force a 
working directory onto the user, much like a cgi-bin, and prepend that 
to sys.path.

> I also agree with Nicolas that there seems to be a message being sent
> when you consider mpservlets, Vampire, his own handler and PSP are all
> doing their own importing mechanism.  Let's face it, importing in
> vanilla python is not the most clear-cut source-inclusion scheme
> around (this is the ONLY area where I think java got it right over
> python); when you imbed it in a process like apache...ouch...

Yes, this abstraction of the interpreter seems to be what causes the 
most confusion. I guess I would summarize it like this:

1. The modules in your URL are imported by Publisher at the root level.
2. The modules in your URL must obey sys.path in their own imports.

Add the sugar (like readily accessible form variables, the req object, 
etc.) and you have Publisher.






More information about the Mod_python mailing list