@@ -159,24 +159,22 @@ The Module Search Path
159159
160160.. index :: triple: module; search; path
161161
162- When a module named :mod: `spam ` is imported, the interpreter searches for a
163- file named :file: `spam.py ` in the directory containing the input script and
164- then in the list of directories specified by the environment variable
165- :envvar: `PYTHONPATH `. This has the same syntax as the shell variable
166- :envvar: `PATH `, that is, a list of directory names. When :envvar: `PYTHONPATH `
167- is not set, or when the file is not found there, the search continues in an
168- installation-dependent default path; on Unix, this is usually
169- :file: `.:/usr/local/lib/python `.
170-
171- Actually, modules are searched in the list of directories given by the variable
172- ``sys.path `` which is initialized from the directory containing the input script
173- (or the current directory), :envvar: `PYTHONPATH ` and the installation- dependent
174- default. This allows Python programs that know what they're doing to modify or
175- replace the module search path. Note that because the directory containing the
176- script being run is on the search path, it is important that the script not have
177- the same name as a standard module, or Python will attempt to load the script as
178- a module when that module is imported. This will generally be an error. See
179- section :ref: `tut-standardmodules ` for more information.
162+ When a module named :mod: `spam ` is imported, the interpreter first searches for
163+ a built-in module with that name. If not found, it then searches for a file
164+ named :file: `spam.py ` in a list of directories given by the variable
165+ :data: `sys.path `. :data: `sys.path ` is initialized from these locations:
166+
167+ * the directory containing the input script (or the current directory).
168+ * :envvar: `PYTHONPATH ` (a list of directory names, with the same syntax as the
169+ shell variable :envvar: `PATH `).
170+ * the installation-dependent default.
171+
172+ After initialization, Python programs can modify :data: `sys.path `. The
173+ directory containing the script being run is placed at the beginning of the
174+ search path, ahead of the standard library path. This means that scripts in that
175+ directory will be loaded instead of modules of the same name in the library
176+ directory. This is an error unless the replacement is intended. See section
177+ :ref: `tut-standardmodules ` for more information.
180178
181179.. %
182180 Do we need stuff on zip files etc. ? DUBOIS
0 commit comments