[Python-bugs-list] [ python-Bugs-500704 ] Tutorial does not describe nested scope

noreply@sourceforge.net noreply@sourceforge.net
Wed, 07 Aug 2002 09:10:22 -0700


Bugs item #500704, was opened at 2002-01-07 22:27
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=500704&group_id=5470

Category: Documentation
Group: Python 2.2
>Status: Closed
>Resolution: Fixed
Priority: 7
Submitted By: Pierre Rouleau (pierre_rouleau)
Assigned to: Raymond Hettinger (rhettinger)
Summary: Tutorial does not describe nested scope

Initial Comment:
The current copy of the tuturial for Python 2.2 states, in chapter 9.2
(Python Scopes and Name Spaces):

"""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."""

I believe the above text should be updated to reflect the fact that Python 2.2 supports nested 
scopes.

----------------------------------------------------------------------

>Comment By: Raymond Hettinger (rhettinger)
Date: 2002-08-07 11:10

Message:
Logged In: YES 
user_id=80475

Added note about read-only variables.
Commited as tut.tex versions 1.167 and 1.156.4.1.2.7
Marking as fixed and closing bug.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-08-07 10:17

Message:
Logged In: YES 
user_id=3066

It's probably worth noting that variables found in outer
non-scopes are read-only:

def outer():
    var = 1
    def inner():
        var = 2
    inner()
    print var

prints 1, not 2.

If you can add a note about that, you should be all set to
check in; no need for further review since I'll see the
checkin msg.

Thanks!

----------------------------------------------------------------------

Comment By: Raymond Hettinger (rhettinger)
Date: 2002-08-05 10:33

Message:
Logged In: YES 
user_id=80475

Patch attached for Fred's approval. If okay, re-assign to 
me and I'll make the same change to the trunk.

----------------------------------------------------------------------

Comment By: Fred L. Drake, Jr. (fdrake)
Date: 2002-03-13 01:03

Message:
Logged In: YES 
user_id=3066

Bumped priority since this can cause real confusion for
someone learning Python.  The corrections need to be part of
Python 2.2.1 and the trunk.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=500704&group_id=5470