[Python-checkins] cpython: Issue #23422: Clarify some things around importlib.import_module()
brett.cannon
python-checkins at python.org
Fri Feb 20 16:34:30 CET 2015
https://hg.python.org/cpython/rev/46bfddb14cbe
changeset: 94701:46bfddb14cbe
user: Brett Cannon <brett at python.org>
date: Fri Feb 20 10:34:20 2015 -0500
summary:
Issue #23422: Clarify some things around importlib.import_module()
files:
Doc/library/importlib.rst | 19 +++++++++++++------
1 files changed, 13 insertions(+), 6 deletions(-)
diff --git a/Doc/library/importlib.rst b/Doc/library/importlib.rst
--- a/Doc/library/importlib.rst
+++ b/Doc/library/importlib.rst
@@ -69,6 +69,10 @@
An implementation of the built-in :func:`__import__` function.
+ .. note::
+ Programmatic importing of modules should use :func:`import_module`
+ instead of this function.
+
.. function:: import_module(name, package=None)
Import a module. The *name* argument specifies what module to
@@ -81,12 +85,15 @@
The :func:`import_module` function acts as a simplifying wrapper around
:func:`importlib.__import__`. This means all semantics of the function are
- derived from :func:`importlib.__import__`, including requiring the package
- from which an import is occurring to have been previously imported
- (i.e., *package* must already be imported). The most important difference
- is that :func:`import_module` returns the specified package or module
- (e.g. ``pkg.mod``), while :func:`__import__` returns the
- top-level package or module (e.g. ``pkg``).
+ derived from :func:`importlib.__import__`. The most important difference
+ between these two functions is that :func:`import_module` returns the
+ specified package or module (e.g. ``pkg.mod``), while :func:`__import__`
+ returns the top-level package or module (e.g. ``pkg``).
+
+ If you are dynamically importing a module that was created since the
+ interpreter began execution (e.g., created a Python source file), you may
+ need to call :func:`invalidate_caches` in order for the new module to be
+ noticed by the import system.
.. versionchanged:: 3.3
Parent packages are automatically imported.
--
Repository URL: https://hg.python.org/cpython
More information about the Python-checkins
mailing list