This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Improve scope example in Tutorial, chapter 9
Type: enhancement Stage:
Components: Documentation Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: docs@python Nosy List: David Goldsmith, docs@python, terry.reedy
Priority: normal Keywords:

Created on 2019-11-03 20:32 by David Goldsmith, last changed 2022-04-11 14:59 by admin.

Messages (2)
msg355908 - (view) Author: David Goldsmith (David Goldsmith) Date: 2019-11-03 20:32
In The Python Tutorial, at the end of Section 9.2.1 "Scopes and Namespaces Example," there occurs the statement: "You can also see that there was no previous binding for spam before the global assignment."  Indeed, one can "virtually see" this by mentally analyzing what the code is doing--if one adequately understood the exposition given in Section 9.2--but, unless it is to be understood by an omission in the example code's output, which is a conclusion I myself am missing, that example code's output does not explicitly validate this claim...and yet, with the addition of just one line to the code, the claim can be shown explicitly: simply copy the line of code:

print("In global scope:", spam)

to precede, as well as follow (as it currently does) the line:

scope_test()

and the code output changes to:

>>> print("In global scope:", spam)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'spam' is not defined
>>> scope_test()
After local assignment: test spam
After nonlocal assignment: nonlocal spam
After global assignment: nonlocal spam
>>> print("In global scope:", spam)
In global scope: global spam  

This does _explicitly_ show that "there was no previous binding for spam before the global assignment": I respectfully suggest that this line be added to the code and that the code's quoted output be suitably updated as well.
msg356272 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2019-11-08 22:58
To me, this is a plausible addition
History
Date User Action Args
2022-04-11 14:59:22adminsetgithub: 82856
2019-11-08 22:58:43terry.reedysetnosy: + terry.reedy
messages: + msg356272
2019-11-08 22:57:50terry.reedysettitle: Sug. for the scope example in TPT Chapter 9 -> Improve scope example in Tutorial, chapter 9
2019-11-03 20:33:18David Goldsmithsettitle: Sug. for the scope example in TPT Cjapter 9 -> Sug. for the scope example in TPT Chapter 9
2019-11-03 20:32:41David Goldsmithcreate