[mod_python] Same name, different directories...

Ian Clelland ian at veryfresh.com
Thu Apr 4 12:07:11 EST 2002


On Thu, Apr 04, 2002 at 03:28:31PM -0300, Javier Quinteros wrote:
> I've defined three Directories in my http.conf, all of them with python 
> scripts inside. What i've noticed is that if I have more than one module 
> called "module1.py" in different directories, mod_python is not able to work 
> with both of them. It seems that it loads the first one (it doesn't matter 
> which one) and after that, if I call the second one is the first one the one 
> who answers me. After that I had to rename some modules just to avoid the 
> possibility that mod_python use them the way he wants.
> 
> Is there any solution? I mean, I don't want to get one interpreter for each 
> Directory I define.

The problem is that Python uses the module's file name -- without 
regard to its path -- as the module's name. A Python interpreter will 
also never load the same module twice, unless you use the 'reload' 
statement.

So the first time you 'import module1', Python loads and runs the first 
module1.py file it can find on sys.path. The second time you run the 
same import statement inside the same interpreter, Python does nothing, 
even if your sys.path is different that time.

It's just the way that Python works (and not mod_python in particular). 
There are probably three ways around this behaviour:

1) Give every module a unique filename.
2) Run seperate Python interpreters to handle different directories.
3) Look into using Python packages.

With packages, you should be able to distinguish between 
identically-named modules in different directories by calling them 
'directory1.module1' and 'directory2.module1'.

Hope this helps,

Ian



More information about the Mod_python mailing list