This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients docs@python, eric.araujo, ezio.melotti, r.david.murray, rhettinger, sandro.tosi, terry.reedy
Date 2011-05-09.22:41:13
SpamBayes Score 3.2474023e-14
Marked as misclassified No
Message-id <1304980882.45.0.903321365653.issue11948@psf.upfronthosting.co.za>
In-reply-to
Content
Sandro, import is a somewhat dark corner of Python that newcomers and even experienced people ofter trip over. So getting the text both correct and clear is worth some thought.

I just noticed that the text is only true for Python-coded modules and not for built-in modules. I discovered this by setting sys.path to {} and importing itertools. It works. It appears that Python first searches for builtins -- I created itertools.py and it did not mask the builtin. If there were a Lib/itertools.py which imported _itertools, it would have been masked. So it appears that the text should begin

"When a module named :mod:`spam` is imported, the interpreter first searches for a built-in module with that name. If not found, it then searches for a file ..."

I suggest changing
"This allows Python programs to modify or replace the module search path."
to
"After initialization, Python programs can modify sys.path."

and changing the followup

" Note that because the directory containing the script being run is on the search path, it is important that the script not have the same name as a standard module, or Python will attempt to load the script as a module when that module is imported.  This will generally be an error."

to something more like

"Because the directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path, the script and other scripts in that directory should not have the same name as a standard library module unless one really intends for the script to be loaded in place of the standard library module."

or perhaps

"The directory containing the script being run is placed at the beginning of the search path, ahead of the standard library path. This means that scripts in that directory will be loaded instead of modules of the same name in the library directory. This is an error unless the replacement is intended."

I think the change to warn about all possibly conflicting scripts in the directory is needed because a common problem people have is more like

import random
a = random.choice('abc')

raising AttributeError ("O python-list, why???") because there is a forgotten random.py in the same directory.
History
Date User Action Args
2011-05-09 22:41:22terry.reedysetrecipients: + terry.reedy, rhettinger, ezio.melotti, eric.araujo, r.david.murray, sandro.tosi, docs@python
2011-05-09 22:41:22terry.reedysetmessageid: <1304980882.45.0.903321365653.issue11948@psf.upfronthosting.co.za>
2011-05-09 22:41:13terry.reedylinkissue11948 messages
2011-05-09 22:41:13terry.reedycreate