Author David Goldsmith
Recipients David Goldsmith, docs@python
Date 2019-11-03.20:32:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
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:


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.
Date User Action Args
2019-11-03 20:32:41David Goldsmithsetrecipients: + David Goldsmith, docs@python
2019-11-03 20:32:41David Goldsmithsetmessageid: <>
2019-11-03 20:32:41David Goldsmithlinkissue38675 messages
2019-11-03 20:32:40David Goldsmithcreate