The documentation for the OS module does not seem to have information about how to open a file that is not in a subdirectory or the current directory that the script is running in without a full path. My directory structure looks like this.
The path given to
open should be relative to the current working directory, the directory from which you run the script. So the above example will only work if you run it from the cgi-bin directory.
A simple solution would be to make your path relative to the script. One possible solution.
import os.path import sys basepath = os.path.dirname(__file__) filepath = os.path.abspath(os.path.join(basepath, "..", "..", "fileIwantToOpen.txt")) f = open(filepath, "r")
This way you'll get the path of the script you're running (basepath) and join that with the relative path of the file you want to open.
os.path will take care of the details of joining the two paths.