Author David Goldsmith
Recipients David Goldsmith, docs@python
Date 2019-11-03.23:31:18
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1572823878.46.0.558548649113.issue38678@roundup.psfhosted.org>
In-reply-to
Content
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 "<stdin>", line 1, in <module>
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?
History
Date User Action Args
2019-11-03 23:31:18David Goldsmithsetrecipients: + David Goldsmith, docs@python
2019-11-03 23:31:18David Goldsmithsetmessageid: <1572823878.46.0.558548649113.issue38678@roundup.psfhosted.org>
2019-11-03 23:31:18David Goldsmithlinkissue38678 messages
2019-11-03 23:31:18David Goldsmithcreate