Nicolas Lehuen
nicolas.lehuen at gmail.com
Fri May 13 02:09:03 EDT 2005
2005/5/13, Graham Dumpleton <grahamd at dscpl.com.au>: [...] > > Using "import main" is not a good idea when the "main.py" is also being > loaded by mod_python by its module loading system. Instead of: > > import main > > use: > > main = apache.import_module("main") > > You may have to use something like: > > import os > > directory = os.path.split(__file__)[0] > main = apache.import_module("main",path=[directory]) > > if wanting to load a module from a location not in sys.path. The latter is > in some ways perfered so as to make sure you get the correct version. > > Hmmm, this all may not work in mod_python 3.2 from what I have > seen of changes to module loading mechanism used specifically for > mod_python.publisher in that version. You may have to replace use of > apache.import_module() with use of publisher specific module loader > in that version when it is available. Indeed. In the upcoming mod_python 3.2, published modules are not imported using apache.import_module, so doing as described above would work BUT the imported module would be another instance of the published one... It would be OK for reusing code but not for sharing data between pages. I didn't think about this use case, I'll have to add a function to the publisher module so that a page can be imported in another page for code reusal or data sharing. Something like publisher.import_page ? Regards, Nicolas
|