[Python-Dev] New and Improved Import Hooks

Fredrik Lundh fredrik@pythonware.com
Wed, 4 Dec 2002 23:42:14 +0100


Just van Rossum wrote:

> (I'd still like to see more examples of code breaking if a sys.path item isn't a
> string. Not that I don't believe it, but I'd like to get an impression of the
> severeness of the damage.)

>From the ImageFont module in PIL 1.1.3:

def load_path(filename):
    "Load a font file, searching along the Python path."
    for dir in sys.path:
        try:
            return load(os.path.join(dir, filename))
        except IOError:
            pass
    raise IOError, "cannot find font file"

(this is fixed in 1.1.4)

FWIW, I've done lots of stuff that scans sys.path directories for
various purposes.  It would probably be a good idea to use a string
subclass for the zip importer, but I don't think we need to make
stringness an absolute requirement.

Let's make it *really* easy to use zip archives, and reasonably easy
to use other custom importers.

</F>