Skip to content

Commit b5942e9

Browse files
slatenyAA-TurnerCAM-Gerlach
authored andcommitted
pythongh-61585: Clarify import scope in modules tutorial (pythonGH-93455)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com> Co-authored-by: CAM Gerlach <CAM.Gerlach@Gerlach.CAM>
1 parent 5e9d3b6 commit b5942e9

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

Doc/tutorial/modules.rst

+11-10
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,9 @@ command::
4747

4848
>>> import fibo
4949

50-
This does not enter the names of the functions defined in ``fibo`` directly in
51-
the current symbol table; it only enters the module name ``fibo`` there. Using
50+
This does not add the names of the functions defined in ``fibo`` directly to
51+
the current :term:`namespace` (see :ref:`tut-scopes` for more details);
52+
it only adds the module name ``fibo`` there. Using
5253
the module name you can access the functions::
5354

5455
>>> fibo.fib(1000)
@@ -75,27 +76,27 @@ These statements are intended to initialize the module. They are executed only
7576
the *first* time the module name is encountered in an import statement. [#]_
7677
(They are also run if the file is executed as a script.)
7778

78-
Each module has its own private symbol table, which is used as the global symbol
79-
table by all functions defined in the module. Thus, the author of a module can
79+
Each module has its own private namespace, which is used as the global namespace
80+
by all functions defined in the module. Thus, the author of a module can
8081
use global variables in the module without worrying about accidental clashes
8182
with a user's global variables. On the other hand, if you know what you are
8283
doing you can touch a module's global variables with the same notation used to
8384
refer to its functions, ``modname.itemname``.
8485

8586
Modules can import other modules. It is customary but not required to place all
8687
:keyword:`import` statements at the beginning of a module (or script, for that
87-
matter). The imported module names are placed in the importing module's global
88-
symbol table.
88+
matter). The imported module names, if placed at the top level of a module
89+
(outside any functions or classes), are added to the module's global namespace.
8990

9091
There is a variant of the :keyword:`import` statement that imports names from a
91-
module directly into the importing module's symbol table. For example::
92+
module directly into the importing module's namespace. For example::
9293

9394
>>> from fibo import fib, fib2
9495
>>> fib(500)
9596
0 1 1 2 3 5 8 13 21 34 55 89 144 233 377
9697

9798
This does not introduce the module name from which the imports are taken in the
98-
local symbol table (so in the example, ``fibo`` is not defined).
99+
local namespace (so in the example, ``fibo`` is not defined).
99100

100101
There is even a variant to import all names that a module defines::
101102

@@ -580,5 +581,5 @@ modules found in a package.
580581
.. rubric:: Footnotes
581582

582583
.. [#] In fact function definitions are also 'statements' that are 'executed'; the
583-
execution of a module-level function definition enters the function name in
584-
the module's global symbol table.
584+
execution of a module-level function definition adds the function name to
585+
the module's global namespace.

0 commit comments

Comments
 (0)