[issue22170] Typo in iterator doc
New submission from Susan Tan: Typo in last line: for line in open("myfile.txt"): print line, Instead there should be no extra "," character in "print line," ---------- assignee: docs@python components: Documentation messages: 225056 nosy: Susan, docs@python priority: normal severity: normal status: open title: Typo in iterator doc type: enhancement versions: Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22170> _______________________________________
Susan Tan added the comment: https://docs.python.org/2/tutorial/classes.html#iterators ---------- _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22170> _______________________________________
Mark Lawrence added the comment: The comma is needed to prevent blank newlines being printed. Please try it for yourself. ---------- nosy: +BreamoreBoy _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22170> _______________________________________
R. David Murray added the comment: The comma means print doesn't add a newline to what is printed. This is correct because the lines read from the file already have a newline at the end. I can see how this example becomes a little confusing in a tutorial section on iterators, but as Mark said, if you try it, you find out that it works, and if you play with removing the comma you learn things about how python works with files (I don't remember how much of that is covered earlier in the tutorial). In python3 this is clearer, because the equivalent line uses end='', making it clearer that it is intentional and meaningful. Except...that in the python3 tutorial it currently *doesn't* use end='', so that example is in fact wrong and needs to be fixed :) ---------- nosy: +r.david.murray stage: -> needs patch type: enhancement -> behavior versions: +Python 3.4, Python 3.5 -Python 2.7 _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22170> _______________________________________
Roundup Robot added the comment: New changeset 35db84720d8d by Ezio Melotti in branch '3.4': #22170: avoid printing newlines twice in tutorial example. http://hg.python.org/cpython/rev/35db84720d8d New changeset 79e469ae13b7 by Ezio Melotti in branch 'default': #22170: merge with 3.4. http://hg.python.org/cpython/rev/79e469ae13b7 ---------- nosy: +python-dev _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22170> _______________________________________
Ezio Melotti added the comment: Fixed, thanks for the report! ---------- assignee: docs@python -> ezio.melotti nosy: +ezio.melotti resolution: -> fixed stage: needs patch -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <http://bugs.python.org/issue22170> _______________________________________
participants (5)
-
Ezio Melotti
-
Mark Lawrence
-
R. David Murray
-
Roundup Robot
-
Susan Tan