[Python-Dev] ImportError on no permission

Georg Brandl g.brandl at gmx.net
Sun May 6 19:23:47 CEST 2007

Today, I got a request regarding importing semantics.

When a module file cannot be opened because of, say, lacking read permission,
the rest of sys.path will be tried, and if nothing else is found, you get
"no module named foo".

The reporter claimed, and I understand that, that this is a pain to debug and
it would be good to at least add a better message to the import error.

Now, why don't we change the semantics as follows: if a file with matching name
exists (in import.c::find_module), but opening fails, ImportError is raised
immediately with the concrete error message, and without trying the rest of
sys.path. That shouldn't cause any working and sane setup to break, or did I
overlook something obvious here?


Thus spake the Lord: Thou shalt indent with four spaces. No more, no less.
Four shall be the number of spaces thou shalt indent, and the number of thy
indenting shall be four. Eight shalt thou not indent, nor either indent thou
two, excepting that thou then proceed to four. Tabs are right out.

More information about the Python-Dev mailing list