PyWart: Import resolution order

Rick Johnson rantingrickjohnson at gmail.com
Fri Jan 11 01:13:26 EST 2013


Python's import resolution order is terrible.[1]

The fact that Python looks in the stdlib _first_ is not a good idea. It would seem more intuitive for a custom "math" module (living in the current directory) to /override/ the stlib "math" module. The proper order is as follows:

1. Current package or directory
2. stdlib
3. under the bed
4. who cares at this point

Look, if you want to keep you foolish imports starting from the stdlib, fine, just create a switch so we can change it to "package/directory" if we like. 

If /only/ the Python gods had placed all stdlib modules in a package named, i don't know, "lib" then none of this would be an issue. You could happily have a stdlib::math and a mylib::math, and when you import either module your code will reflect that path explicitly. Hmm, this last sentence reminded me of something??? Oh yes -> "Explicit is better than implicit".


[1]: Yes, yes, i know about sys.path.insert. *puke*!



More information about the Python-list mailing list