Graham Dumpleton
grahamd at dscpl.com.au
Tue Jun 13 18:57:39 EDT 2006
Richard Lewis wrote .. > On Tuesday 13 June 2006 00:39, Graham Dumpleton wrote: > > 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. Where importing "a/b" targeting "a/b.py", is there also a "a/__init__.py"? In other words, is the directory "a" properly setup as a Python package with an "__init__.py" file? If not, then '.' notation wouldn't work but '/' may (at least for that platform). Graham
|