Find the location of a loaded module

Aaron Scott aaron.hildebrandt at gmail.com
Fri Feb 20 22:24:00 CET 2009


Son of a bitch. It gets worse.

> Executed from inside 'act1', which contains the directory / module
> 'story':
>
>         directory = os.path.dirname(__file__)
>         req.write(str(directory))
>         story = apache.import_module('story', path=[directory])
>
> Results:
>
>   /home/www/---/docs/act1
>
>   File "/home/www/---/docs/act1/play.py", line 24, in Rebuild
>     storylab = apache.import_module('story', path=[directory])
>
>   File "/usr/local/python2.5.2/lib/python2.5/site-packages/mod_python/
> importer.py", line 304, in import_module
>     return __import__(module_name, {}, {}, ['*'])
>
> ImportError: No module named story
>

If I execute the exact same code from the 'act1' directory after
running it from the 'act2' directory, it successfully loads the
'story' module... from 'act2'. Even though I used the Apache importer
to specify the EXACT LOCATION of the module to import.

'req.write(str(os.path.dirname(__file__)))' returns '/home/www/---/
docs/act1'.

'req.write(story.game.Save())' returns '/home/www/--/docs/act2/
storylab/game.pyc' as the file being accessed.

BLOODY HELL.

Okay, deep breath.

Does anyone know what's going on? Am I just not understanding how
module importing in mod_python works? I'd really appreciate help,
since I'll be stuck at work today until I can get this sorted out, and
I've long since run out of ideas.



More information about the Python-list mailing list