diff options
author | Raymond Hettinger <python@rcn.com> | 2002-08-07 16:09:48 (GMT) |
---|---|---|
committer | Raymond Hettinger <python@rcn.com> | 2002-08-07 16:09:48 (GMT) |
commit | 861bb0244807df6642c19dcc99c54be29c69b0fa (patch) | |
tree | 3e42119715245b38efbae759b19772b01e0e7ec9 /Doc | |
parent | 29bf9157ec8840caa74baf99d431394137749186 (diff) | |
download | cpython-861bb0244807df6642c19dcc99c54be29c69b0fa.zip cpython-861bb0244807df6642c19dcc99c54be29c69b0fa.tar.gz cpython-861bb0244807df6642c19dcc99c54be29c69b0fa.tar.bz2 |
Describe nested scopes in the tutorial. Closes SF bug 500704.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/tut/tut.tex | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/Doc/tut/tut.tex b/Doc/tut/tut.tex index 1e5774b..b7a9090 100644 --- a/Doc/tut/tut.tex +++ b/Doc/tut/tut.tex @@ -3551,12 +3551,17 @@ that an unqualified reference to a name attempts to find the name in the namespace. Although scopes are determined statically, they are used dynamically. -At any time during execution, exactly three nested scopes are in use -(exactly three namespaces are directly accessible): the -innermost scope, which is searched first, contains the local names, -the middle scope, searched next, contains the current module's global -names, and the outermost scope (searched last) is the namespace -containing built-in names. +At any time during execution, there are at least three nested scopes whose +namespaces are directly accessible: the innermost scope, which is searched +first, contains the local names; the namespaces of any enclosing code +blocks (a module, function, or class definition) which are searched starting +with the nearest enclosing scope; the middle scope, searched next, contains +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) current function. Outside of functions, the local scope references |