PyWart: Import resolution order

Terry Reedy tjreedy at udel.edu
Fri Jan 11 14:35:37 CET 2013


On 1/11/2013 1:13 AM, Rick Johnson wrote:
>
> Python's import resolution order is terrible.[1]
>
> The fact that Python looks in the stdlib _first_ is not a good idea.

And the fact is that it does not do so. The order depends on sys.path, 
and '' is the first entry.

> It would seem more intuitive for a custom "math" module (living in
> the current directory) to /override/ the stlib "math" module.

Try it.

This is a nuisance though, when not intended. Someone writes a 
random.py, and a year later in the same directory, an unrelated 
hopscotch.py, which tries to import random.exponential. The import fails 
and they post here, having forgotten about their own random.py, which 
does not have such a function. Posts like this happen a few times a year.

-- 
Terry Jan Reedy




More information about the Python-list mailing list