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

Skip to content

Commit 2a082ad

Browse files
committed
Clarify that one should not use __import__() directly. Also mention
PEP 328 in explaining how 'index' works.
1 parent 49f8d8b commit 2a082ad

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

Doc/library/functions.rst

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,8 +1447,9 @@ are always available. They are listed here in alphabetical order.
14471447
replaced (by importing the :mod:`builtins` module and assigning to
14481448
``builtins.__import__``) in order to change semantics of the
14491449
:keyword:`import` statement, but nowadays it is usually simpler to use import
1450-
hooks (see :pep:`302`). Direct use of :func:`__import__` is rare, except in
1451-
cases where you want to import a module whose name is only known at runtime.
1450+
hooks (see :pep:`302`) to attain the same goals. Direct use of
1451+
:func:`__import__` is entirely discouraged in favor of
1452+
:func:`importlib.import_module`.
14521453

14531454
The function imports the module *name*, potentially using the given *globals*
14541455
and *locals* to determine how to interpret the name in a package context.
@@ -1460,7 +1461,8 @@ are always available. They are listed here in alphabetical order.
14601461
*level* specifies whether to use absolute or relative imports. ``0`` (the
14611462
default) means only perform absolute imports. Positive values for
14621463
*level* indicate the number of parent directories to search relative to the
1463-
directory of the module calling :func:`__import__`.
1464+
directory of the module calling :func:`__import__` (see :pep:`328` for the
1465+
details).
14641466

14651467
When the *name* variable is of the form ``package.module``, normally, the
14661468
top-level package (the name up till the first dot) is returned, *not* the

0 commit comments

Comments
 (0)