[issue10304] error in tutorial triple-string example
New submission from Malte Helmert <helmert@informatik.uni-freiburg.de>:
From Section 3.1.2 of the tutorial:
print(""" Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to """) produces the following output: _____________________________________________________________ Usage: thingy [OPTIONS] -h Display this usage message -H hostname Hostname to connect to _____________________________________________________________ That doesn't quite match the behaviour: there should be an extra blank line prepended to the output. ---------- assignee: docs@python components: Documentation messages: 120364 nosy: docs@python, maltehelmert priority: normal severity: normal status: open title: error in tutorial triple-string example versions: Python 3.2 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
Changes by Ezio Melotti <ezio.melotti@gmail.com>: ---------- nosy: +ezio.melotti _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
Malte Helmert <helmert@informatik.uni-freiburg.de> added the comment: Here's a related one if you want to get the sample output really 100% correct. In the last example of Section 3, the output in {>>> a, b = 0, 1
while b < 1000: ... print(b, end=' ') ... a, b = b, a+b ... 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987}
should have an extra space at the end. (Granted, this is very very minor, but this may make a Python 2.x oldtimer like me wonder if print's end=" " does the same as old Python 2.x's "print b," including suppression of the "softspace".) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: 1. Rather than add a blank line to the output, the input should have the newline suppressed with \ (which has been done in previous examples). print("""\ 2. It is rather difficult to see that there is no blank at the end (highlight with mouse). I can imagine that either the formatter or display system might delete even if in the master .rst file. In interactive use, the interpreter will go to a new line anyway before printing the >>> prompt. The intent and effect of end=' ' is that the outputs are all on one line (as with 2.x print) instead of each on a separate line ---------- nosy: +terry.reedy stage: -> needs patch _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
Changes by Terry J. Reedy <tjreedy@udel.edu>: ---------- keywords: +easy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
Malte Helmert <helmert@informatik.uni-freiburg.de> added the comment:
1. Rather than add a blank line to the output, the input should have the newline suppressed with \ (which has been done in previous examples). print("""\
I think that would be didactically bad after just mentioning that newlines in triple-quoted strings don't have to be escaped etc. I think this would confuse the reader. Better use print("""Usage...
In interactive use, the interpreter will go to a new line anyway before printing the >>> prompt.
It won't (at least in Python 3.1). I just tried it.
The intent and effect of end=' ' is that the outputs are all on one line (as with 2.x print) instead of each on a separate line
Sure. But I think that in an example that is essentially about whitespace produced by print, the actual whitespace in the output should match the actual behaviour of print. One why to get rid of this problem altogether is to add a 'print "done!"' or whatever at the end, or use a different separator from " ". ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
R. David Murray <rdmurray@bitdance.com> added the comment: I think the commit hook might object to the trailing blank (I'm not sure it applies to rst files, but I think it does). ---------- nosy: +r.david.murray _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: I should have said that IDLE puts >>> on a new line. ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
Malte Helmert <helmert@informatik.uni-freiburg.de> added the comment: I see. (The tutorial really talks about the interactive interpreter though -- I don't think IDLE has been mentioned yet.) ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
Terry J. Reedy <tjreedy@udel.edu> added the comment: 1. I decided to add '\' since this is what I normally do and also add one sentence explanation. 2. I changed ending from ' ' to ','. Uploaded patch committed in rev86422, rev86423 ---------- keywords: +patch resolution: -> fixed stage: needs patch -> committed/rejected status: open -> closed versions: +Python 3.1 Added file: http://bugs.python.org/file19575/Issue 10304.diff _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue10304> _______________________________________
participants (4)
-
Ezio Melotti
-
Malte Helmert
-
R. David Murray
-
Terry J. Reedy