Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ee2df03

Browse files
author
Michael Foord
committed
Tutorial tweaks. Issue 6849.
1 parent 668be58 commit ee2df03

1 file changed

Lines changed: 10 additions & 12 deletions

File tree

Doc/tutorial/modules.rst

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,10 @@ There is even a variant to import all names that a module defines::
103103

104104
This imports all names except those beginning with an underscore (``_``).
105105

106+
Note that in general the practice of importing ``*`` from a module or package is
107+
frowned upon, since it often causes poorly readable code. However, it is okay to
108+
use it to save typing in interactive sessions.
109+
106110
.. note::
107111

108112
For efficiency reasons, each module is only imported once per interpreter
@@ -443,14 +447,9 @@ Importing \* From a Package
443447

444448
Now what happens when the user writes ``from sound.effects import *``? Ideally,
445449
one would hope that this somehow goes out to the filesystem, finds which
446-
submodules are present in the package, and imports them all. Unfortunately,
447-
this operation does not work very well on Windows platforms, where the
448-
filesystem does not always have accurate information about the case of a
449-
filename. On these platforms, there is no guaranteed way to know whether a file
450-
:file:`ECHO.PY` should be imported as a module :mod:`echo`, :mod:`Echo` or
451-
:mod:`ECHO`. (For example, Windows 95 has the annoying practice of showing all
452-
file names with a capitalized first letter.) The DOS 8+3 filename restriction
453-
adds another interesting problem for long module names.
450+
submodules are present in the package, and imports them all. This could take a
451+
long time and importing sub-modules might have unwanted side-effects that should
452+
only happen when the sub-module is explicitly imported.
454453

455454
The only solution is for the package author to provide an explicit index of the
456455
package. The :keyword:`import` statement uses the following convention: if a package's
@@ -485,10 +484,9 @@ current namespace because they are defined in the :mod:`sound.effects` package
485484
when the ``from...import`` statement is executed. (This also works when
486485
``__all__`` is defined.)
487486

488-
Note that in general the practice of importing ``*`` from a module or package is
489-
frowned upon, since it often causes poorly readable code. However, it is okay to
490-
use it to save typing in interactive sessions, and certain modules are designed
491-
to export only names that follow certain patterns.
487+
Although certain modules are designed to export only names that follow certain
488+
patterns when you use ``import *``, it is still considered bad practise in
489+
production code.
492490

493491
Remember, there is nothing wrong with using ``from Package import
494492
specific_submodule``! In fact, this is the recommended notation unless the

0 commit comments

Comments
 (0)