[Python-Dev] New and Improved Import Hooks

Just van Rossum just@letterror.com
Wed, 4 Dec 2002 12:52:39 +0100


Fredrik Lundh wrote:

> what's wrong with:
> 
> #4
>     for path in sys.path:
>         if isinstance(path, types.StringTypes):
>             do_standard_import(...)
>         else:
>             path.do_import(...)

That, or what Jack said, which I think is even better:

#5
    for path in sys.path:
        if hasattr(path, "find_module"):
            loader = path.find_module(name)
        if isinstance(path, types.StringTypes):
            do_standard_import(...)
        else:
            pass

(I originally thought it might be important that path elements be str
subclasses, but I'm not so sure anymore. Especially after I wrote a str subclass
in C: it's a HUGE pain ;-)

Just