Relative paths in mod_python

Steve Holden steve at
Sun Mar 19 22:32:15 CET 2006

Ivo van der Sangen wrote:
> I was wondering if I could use relative paths in a mod_python script. At
> the moment I am defining a constant string
> "/path/to/dir/where/script/resides". The problem with this is that when
> I move the script including files I use to get metadata I have to change
> this variable. The same problem occurs when I distribute the script; the
> person using it will first have to modify it, which is not what I want. Is
> it possible that a mod_python script has as current working directory
> the directory where the script resides? At the moment os.getcwd()
> returns '/'.

     import os

seems to give you the absolute path to the module you are executing. You 
can use the other os.path primitives to extract the directory from that 
and use it to locate the associated data files.

Steve Holden       +44 150 684 7255  +1 800 494 3119
Holden Web LLC/Ltd       
Love me, love my blog

More information about the Python-list mailing list