[Python-Dev] New and Improved Import Hooks
Just van Rossum
just@letterror.com
Thu, 5 Dec 2002 10:41:20 +0100
M.-A. Lemburg wrote:
> Why not leave sys.path as list of ordinary strings and add
> all the extra support to the existing import mechanism via
> hooks at the right places ?!
>
> E.g. such a hook may scan sys.path for files which end
> in '.zip' and then redirect the lookups into their ZIP
> archive directory.
Then you get the problem that Samuele pointed out: if the *hook* scans sys.path
you get a funny path resolution order: hooks[0] may find the module on
sys.path[3] before hooks[2] finds it on sys.path[2].
We should document that
- sys.path *may* contain arbitrary objects, and that sys.path traversing
code should be careful.
- the std library promises to not add objects to sys.path that are not
isinstance(p, (str, unicode)).
I think this is the perfect compromise. Thank you </F>!
Just