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

Skip to content

Commit 3fa8422

Browse files
committed
Issue #23422: Clarify some things around importlib.import_module()
1 parent 16cd19c commit 3fa8422

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

Doc/library/importlib.rst

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Functions
6969

7070
An implementation of the built-in :func:`__import__` function.
7171

72+
.. note::
73+
Programmatic importing of modules should use :func:`import_module`
74+
instead of this function.
75+
7276
.. function:: import_module(name, package=None)
7377

7478
Import a module. The *name* argument specifies what module to
@@ -81,12 +85,15 @@ Functions
8185

8286
The :func:`import_module` function acts as a simplifying wrapper around
8387
:func:`importlib.__import__`. This means all semantics of the function are
84-
derived from :func:`importlib.__import__`, including requiring the package
85-
from which an import is occurring to have been previously imported
86-
(i.e., *package* must already be imported). The most important difference
87-
is that :func:`import_module` returns the specified package or module
88-
(e.g. ``pkg.mod``), while :func:`__import__` returns the
89-
top-level package or module (e.g. ``pkg``).
88+
derived from :func:`importlib.__import__`. The most important difference
89+
between these two functions is that :func:`import_module` returns the
90+
specified package or module (e.g. ``pkg.mod``), while :func:`__import__`
91+
returns the top-level package or module (e.g. ``pkg``).
92+
93+
If you are dynamically importing a module that was created since the
94+
interpreter began execution (e.g., created a Python source file), you may
95+
need to call :func:`invalidate_caches` in order for the new module to be
96+
noticed by the import system.
9097

9198
.. versionchanged:: 3.3
9299
Parent packages are automatically imported.

0 commit comments

Comments
 (0)