module search path
jepler at unpythonic.net
Sat Jul 31 18:53:56 CEST 2004
... because ".." is relative to os.getcwd(), and the httpd doesn't
change to the user directory before starting the cgi script?
os.dirname(__file__) should tell you the directory where the current
module resides, as would sys.argv:
$ cat /tmp/ajay.py
$ python /tmp/ajay.py
So you could write something like
# near the top of index.cgi
cgidir = dirname(__file__)
commondir = os.path.join(cgidir, os.pardir, "common")
or you might be able to change the the directory where the cgi script
if you prefer.
Anyway, __file__ is the trick you need to know about. It is documented:
.. but maybe not where you looked for it, if you even suspected it
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Size: 196 bytes
Desc: not available
More information about the Python-list