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: Python Tutorial 4.7.1: Improve ask_ok() to cover more input values
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.6, Python 3.5
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: amyluo, benjamin.peterson, berker.peksag, docs@python, fdrake, python-dev, willingc
Priority: normal Keywords: patch

Created on 2014-12-26 19:42 by amyluo, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue23116.diff berker.peksag, 2016-06-01 18:27 review
Messages (8)
msg233114 - (view) Author: Amy (amyluo) Date: 2014-12-26 19:42
https://docs.python.org/3/tutorial/controlflow.html#default-argument-values
def ask_ok(prompt, retries=4, complaint='Yes or no, please!'):
    while True:
        ok = input(prompt)

Suggestion: change to "ok = input(prompt).lower()" in order to cover values with capitalized characters such as "Yes" or "NO".
msg233354 - (view) Author: Carol Willing (willingc) * (Python committer) Date: 2015-01-03 12:18
@amylou Thank you for submitting this documentation suggestion about the Python Tutorial.

This tutorial section, 4.7.1 Default Argument Values, tries to show that a function can have multiple input arguments which may be given default values.

While the suggestion to use lower() does offer more robust input handling, it also adds some complexity to the example by introducing another function to a possibly new user.

I do believe that the 'ask_ok' function could be improved by renaming the 'complaint' argument to something more positive, perhaps 'reminder'. I would also recommend replacing the error message 'uncooperative user' to something with a softer tone, perhaps 'invalid user response'.

@amyluo If you are interested in working on documentation, section 6 of the Developer Guide is a handy resource (https://docs.python.org/devguide/docquality.html).
msg266831 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-06-01 18:16
I agree with all of Carol's suggestions. Also, OSError could be replaced with a more appropriate exception such as ValueError.
msg266833 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2016-06-01 18:22
+1 for ValueError instead of OSError.
msg266834 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-06-01 18:27
Here is a patch.
msg266888 - (view) Author: Benjamin Peterson (benjamin.peterson) * (Python committer) Date: 2016-06-02 16:51
I think the patch is okay except for the use of "-=" instead of the more verbose version.
msg266899 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2016-06-02 18:21
New changeset ef800c30e28c by Berker Peksag in branch '3.5':
Issue #23116: Improve ask_ok() example in the Python tutorial
https://hg.python.org/cpython/rev/ef800c30e28c

New changeset 174eae50b664 by Berker Peksag in branch 'default':
Issue #23116: Merge from 3.5
https://hg.python.org/cpython/rev/174eae50b664
msg266900 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2016-06-02 18:22
Thanks for the review. I removed the "-=" part from the patch.
History
Date User Action Args
2022-04-11 14:58:11adminsetgithub: 67305
2016-06-02 18:22:46berker.peksagsetstatus: open -> closed
resolution: fixed
messages: + msg266900

stage: patch review -> resolved
2016-06-02 18:21:35python-devsetnosy: + python-dev
messages: + msg266899
2016-06-02 16:51:11benjamin.petersonsetnosy: + benjamin.peterson
messages: + msg266888
2016-06-01 18:27:34berker.peksagsetfiles: + issue23116.diff
keywords: + patch
messages: + msg266834

stage: needs patch -> patch review
2016-06-01 18:22:19fdrakesetnosy: + fdrake
messages: + msg266833
2016-06-01 18:16:38berker.peksagsetversions: + Python 3.5, Python 3.6, - Python 3.4
nosy: + berker.peksag

messages: + msg266831

stage: needs patch
2015-01-03 12:18:03willingcsetnosy: + docs@python, willingc
messages: + msg233354

assignee: docs@python
components: + Documentation
2014-12-26 19:42:14amyluocreate