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

Skip to content

Commit 2b9fd47

Browse files
committed
Fix docs for __import__ that say the default for 'level' is -1; it's actually
0.
1 parent a113ac5 commit 2b9fd47

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

Doc/library/functions.rst

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,9 +1207,8 @@ are always available. They are listed here in alphabetical order.
12071207
not use its *locals* argument at all, and uses its *globals* only to
12081208
determine the package context of the :keyword:`import` statement.
12091209

1210-
*level* specifies whether to use absolute or relative imports. The default
1211-
is ``-1`` which indicates both absolute and relative imports will be
1212-
attempted. ``0`` means only perform absolute imports. Positive values for
1210+
*level* specifies whether to use absolute or relative imports. ``0`` (the
1211+
default) means only perform absolute imports. Positive values for
12131212
*level* indicate the number of parent directories to search relative to the
12141213
directory of the module calling :func:`__import__`.
12151214

@@ -1221,19 +1220,19 @@ are always available. They are listed here in alphabetical order.
12211220
For example, the statement ``import spam`` results in bytecode resembling the
12221221
following code::
12231222

1224-
spam = __import__('spam', globals(), locals(), [], -1)
1223+
spam = __import__('spam', globals(), locals(), [], 0)
12251224

12261225
The statement ``import spam.ham`` results in this call::
12271226

1228-
spam = __import__('spam.ham', globals(), locals(), [], -1)
1227+
spam = __import__('spam.ham', globals(), locals(), [], 0)
12291228

12301229
Note how :func:`__import__` returns the toplevel module here because this is
12311230
the object that is bound to a name by the :keyword:`import` statement.
12321231

12331232
On the other hand, the statement ``from spam.ham import eggs, sausage as
12341233
saus`` results in ::
12351234

1236-
_temp = __import__('spam.ham', globals(), locals(), ['eggs', 'sausage'], -1)
1235+
_temp = __import__('spam.ham', globals(), locals(), ['eggs', 'sausage'], 0)
12371236
eggs = _temp.eggs
12381237
saus = _temp.sausage
12391238

0 commit comments

Comments
 (0)