[issue38675] Sug. for the scope example in TPT Cjapter 9
New submission from David Goldsmith : 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 "", line 1, in 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 <https://bugs.python.org/issue38675> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38675] Sug. for the scope example in TPT Chapter 9
Change by David Goldsmith : -- title: Sug. for the scope example in TPT Cjapter 9 -> Sug. for the scope example in TPT Chapter 9 ___ Python tracker <https://bugs.python.org/issue38675> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue38678] TypeError raised trying to run TPT 10.3 Example 2 in Python 3.4.3
New submission from David Goldsmith : When I run the second example code of Section 10.3 of The Python Tutorial: import argparse from getpass import getuser parser = argparse.ArgumentParser(description='An argparse example.') parser.add_argument('name', nargs='?', default=getuser(), help='The name of someone to greet.') parser.add_argument('--verbose', '-v', action='count') args = parser.parse_args() greeting = ["Hi", "Hello", "Greetings! its very nice to meet you"][args.verbose % 3] print(f'{greeting}, {args.name}') if not args.verbose: print('Try running this again with multiple "-v" flags!') the greeting assignment line raises: >>> greeting = ["Hi", "Hello", "Greetings! its very nice to meet >>> you"][args.verbose % 3] Traceback (most recent call last): File "", line 1, in TypeError: unsupported operand type(s) for %: 'NoneType' and 'int' Is this an artifact of me being so far behind in my Python version: Davids-MacBook-Air:~ DLG$ python3 Python 3.4.3 |Anaconda 2.4.0 (x86_64)| (default, Oct 20 2015, 14:27:51) [GCC 4.2.1 (Apple Inc. build 5577)] on darwin Or is it a bug in the example code in the doc? -- assignee: docs@python components: Documentation messages: 355914 nosy: David Goldsmith, docs@python priority: normal severity: normal status: open title: TypeError raised trying to run TPT 10.3 Example 2 in Python 3.4.3 type: crash ___ Python tracker <https://bugs.python.org/issue38678> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com