|
Richard Lewis
richardlewis at fastmail.co.uk
Wed Jun 14 04:23:12 EDT 2006
On Tuesday 13 June 2006 23:57, Graham Dumpleton wrote:
> 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"?
>
No, there isn't.
> 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).
>
I see. I hand't really understood that that was necessary before.
I think I'll try and leave it as it is, though. Because the Python code being
imported here is a custom, optional user-defined module which implements a
xml.sax.handler.ContenHandler class. Its in a directory which also contains
user-defined XSLT stylesheets and is named by the user in the sitemap.xml
configuration file as a "transformer" for a "pipeline". So its not really a
package, just an imported class.
Thanks for your help.
Cheers,
Richard
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-
Richard Lewis
Sonic Arts Research Archive
http://www.sara.uea.ac.uk/
-=-=-=-=-=-=-=-=-=-=-=-=-=-
|