[mod_python] __import__ error

Richard Lewis richardlewis at fastmail.co.uk
Tue Jun 13 09:08:48 EDT 2006


On Tuesday 13 June 2006 00:39, Graham Dumpleton wrote:
> When import in mod_python is done, it will not necessarily look in
> current
> working directory anyway. You need to add directory to Python PATH
> explicitly using the directive:
>
>   PythonPath 'sys.path+["/var/www-studio/"]'
>
> in your Apache configuration for where you are using mod_python.

OK, I've added this and it works, but...

> > _>>> sf = __import__(module.replace(".", os.sep)).__dict__[handler]()
>
> Note that using 'os.sep' in module naming hierarchy only works on some
> platforms when using __import__ and thus is not portable. It may work
> on Linux, but doesn't work on Mac OS X. Don't know if it works on Win32
> or not.
>
...only if I continue to use os.sep. I've put it in a try block like this:

try:
  self.handler = __import__(module).__dict__[handler]()
except ImportError:
  self.handler = __import__(module.replace(".", os.sep)).__dict__[handler]()

but it always uses the exception case. I haven't tried it with OS X or Windows 
yet. Perhaps they'll use the first case properly.

Thanks for your help.

Cheers,
Richard
-- 
-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
Sonic Arts Research Archive
http://www.sara.uea.ac.uk/
-=-=-=-=-=-=-=-=-=-=-=-=-=-


More information about the Mod_python mailing list