Graham Dumpleton
graham.dumpleton at gmail.com
Sat Apr 19 00:11:09 EDT 2008
2008/4/18 Victor Subervi <victorsubervi at gmail.com>: > > On Thu, Apr 17, 2008 at 6:23 PM, Graham Dumpleton > <graham.dumpleton at gmail.com> wrote: > > > > > 2008/4/18 Joseph Bernhardt <joe at incomps.com>: > > > > > > > 2008/4/18 Joseph Bernhardt <joe at incomps.com>: > > > > > > > > > > > > > > > > > > > > > > > > > 1) How do I import a file in the same folder as the script which is > > > > > importing? This does not work: > > > > > > > > > > Is this directory in your module path? sys.path > > > This is what ended up working... > > import sys,os > sys.path.append(os.getcwd()) > from example import example That is wrong. You cannot rely on os.getcwd() value as under Apache it could be anything, although would usually be '/' because Apache generally sets current working directory to root of filesystem. So, unless your code was elsewhere setting the current working directory, can't see how that would work. If you are setting the current working directory, be aware that you shouldn't do that either when using Apache as it is a shared application environment and doubly would cause problems if multithreading is also used. If you need to work out a path relative to where a source file is, you calculate it using: here = os.path.dirname(__file__) You should not however add such a directory to sys.path if the source code file was one which mod_python imported using its module importing mechanism as you will then have an overlap and you could end up with the same source file being imported multiple times under different names. Is 'example' actually a package? Have you tried moving it outside of the document tree and then setting sys.path or using PythonPath like I said in other email? Graham > Concerning the problems with errors (IntegrityError, OperationalError), I > have indeed imported MySQLdb, but that does not resolve the problem. Other > ideas?
|