mirror of
https://github.com/python/cpython.git
synced 2025-09-14 04:37:29 +00:00
Describe nested scopes in the tutorial. Closes SF bug 500704.
This commit is contained in:
parent
29bf9157ec
commit
861bb02448
1 changed files with 11 additions and 6 deletions
|
@ -3551,12 +3551,17 @@ that an unqualified reference to a name attempts to find the name in
|
||||||
the namespace.
|
the namespace.
|
||||||
|
|
||||||
Although scopes are determined statically, they are used dynamically.
|
Although scopes are determined statically, they are used dynamically.
|
||||||
At any time during execution, exactly three nested scopes are in use
|
At any time during execution, there are at least three nested scopes whose
|
||||||
(exactly three namespaces are directly accessible): the
|
namespaces are directly accessible: the innermost scope, which is searched
|
||||||
innermost scope, which is searched first, contains the local names,
|
first, contains the local names; the namespaces of any enclosing code
|
||||||
the middle scope, searched next, contains the current module's global
|
blocks (a module, function, or class definition) which are searched starting
|
||||||
names, and the outermost scope (searched last) is the namespace
|
with the nearest enclosing scope; the middle scope, searched next, contains
|
||||||
containing built-in names.
|
the current module's global names; and the outermost scope (searched last)
|
||||||
|
is the namespace containing built-in names.
|
||||||
|
|
||||||
|
If a name is declared global, then all references and assignments go
|
||||||
|
directly to the middle scope containing the module's global names.
|
||||||
|
Otherwise, all variables found outside of the innermost scope are read-only.
|
||||||
|
|
||||||
Usually, the local scope references the local names of the (textually)
|
Usually, the local scope references the local names of the (textually)
|
||||||
current function. Outside of functions, the local scope references
|
current function. Outside of functions, the local scope references
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue