New submission from David Goldsmith <[email protected]>:
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.
----------
assignee: docs@python
components: Documentation
messages: 355908
nosy: David Goldsmith, docs@python
priority: normal
severity: normal
status: open
title: Sug. for the scope example in TPT Cjapter 9
type: enhancement
versions: Python 3.8
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue38675>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com