[ python-Bugs-997912 ] Enclosing Scope missing from namespace in
Tutorial
SourceForge.net
noreply at sourceforge.net
Mon Jul 26 11:39:38 CEST 2004
Bugs item #997912, was opened at 2004-07-26 05:39
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=997912&group_id=5470
Category: Documentation
Group: Python 2.3
Status: Open
Resolution: None
Priority: 5
Submitted By: Brian vdB (brianvanden)
Assigned to: Nobody/Anonymous (nobody)
Summary: Enclosing Scope missing from namespace in Tutorial
Initial Comment:
In the docs to Python 2.3.4 (#53, May 25 2004,
21:17:02), Section 4.6 of the Python Tutorial says:
The execution of a function introduces a new symbol
table used for the local variables of the function.
More precisely, all variable assignments in a function
store the value in the local symbol table; whereas
variable
references first look in the local symbol table, then
in the global symbol table, and then in the table of
built-in names. Thus, global variables cannot be
directly assigned a value within a function (unless
named in a
global statement), although they may be referenced.
This doesn't make it clear that in the following sort
of case, the nested def can 'see' the varriables in the
topmost function:
>>> spam = 1
>>> def foo():
spam = 2
ham = 3
def bar():
print spam, ham
bar()
>>> foo()
2 3
I suggest the following ammendment:
. . . whereas variable references first look in the
local symbol table, then in the local scope of the
enclosing function defs (if any), then in the global
symbol table, . . .
Thanks,
Brian vdB
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=997912&group_id=5470
More information about the Python-bugs-list
mailing list