[mod_python] relative paths in psp

Noel Taylor nttaylor at cs.uchicago.edu
Thu Jun 3 18:29:46 EDT 2004


Hello all,

I'm trying to embed python in html using mod_python.

I've gotten it up and running successfully, but I have a question about
opening files and relative paths from within the embedded python script.

If myfile.psp is as follows:

<html>
<%
f = open('insertthis.html','rb').read()
req.write(f)
%>
</html>

I get a "no such file" error on 'insertthis.html', which is not such a
mystery since displaying sys.path reveals it as:

/usr/lib/python23.zip/usr/lib/python2.3/usr/lib/python2.3/plat-linux2/usr/lib/python2.3/lib-tk/usr/lib/python2.3/lib-dynload/usr/lib/python2.3/site-packages

So I can make the above code work if I use an absolute path, but is there
any way to make it work using a relative path, where '.' is understood to
be the directory where the .psp file is located?

with thanks,

nttaylor


More information about the Mod_python mailing list