[mod_python] Current Working Directory not set?

Sean Jamieson sean at barriescene.com
Fri Jan 27 14:53:27 EST 2006

Hello everybody,
I don't know if there's already been a discussion about this, it seems 
like a small but obvious issue.

The current working directory does not apear to be set when a 
mod_python.publisher script runs; or rather it's set to "/" which is not 
useful. This becomes quite a pain, as I'm forced to do many things to 
work around it.
1) I've started using kid templates, and I have to use:
     Template( file=req.document_root().'template.kid', ... )
file=req.document_root().'project_dir/templates/template.kid', ... )
rather then the more natural:
    Template( file='templates/template.kid )
this should find the 'templates' directory in the same directory as the 
running script

2) I have to fully qualify imports from the document root, as the 
document root is added to sys.modules, but the current directory is not. 
So, if I'm in a subdirectory under the document root I have to do:
    import project_dir.subpackage.module
when the current directory is 'project_dir'. This is silly, I should be 
able to import something in, or under, the current working directory:
    import subpackage.module
I would have to do some hack involving seperating the dirname of 
__file__ and adding it to sys.modules


More information about the Mod_python mailing list