[Import-sig] Why add '' to sys.path if there's an __init__.py?
Fred L. Drake, Jr.
fdrake@beopen.com
Mon, 2 Oct 2000 19:34:10 -0400 (EDT)
This relates to SourceForge bug report #115528:
http://sourceforge.net/bugs/?func=detailbug&bug_id=115528&group_id=5470
This reports a problem that I vaguely recall having heard complaints
about before. Essentially, the user is running Python with a script
stored in the same directory as the contents of a package:
foo/__init__.py
module.py
script.py
The complaint is that "module" can be imported as "module" (in the
top-level "unnamed" package), and as "foo.module", where it should
be. I don't think this is actually a bug (which is why I've closed
the report), but it is clearly something that gets in the way of real
users.
I think we get better behavior if we remove '' from sys.path if
there's an __init__.py file present; importing foo.module would still
work, but import module would raise an ImportError exception.
Comments please!
-Fred
--
Fred L. Drake, Jr. <fdrake at beopen.com>
BeOpen PythonLabs Team Member