Commit 6ef1767f authored by Andrew Svetlov's avatar Andrew Svetlov

Drop double newlines printed in some file iteration examples.

Patch by Steven Kryskalla.
parent 349106ba
...@@ -387,7 +387,7 @@ succeeded or failed. Look at the following example, which tries to open a file ...@@ -387,7 +387,7 @@ succeeded or failed. Look at the following example, which tries to open a file
and print its contents to the screen. :: and print its contents to the screen. ::
for line in open("myfile.txt"): for line in open("myfile.txt"):
print(line) print(line, end="")
The problem with this code is that it leaves the file open for an indeterminate The problem with this code is that it leaves the file open for an indeterminate
amount of time after this part of the code has finished executing. amount of time after this part of the code has finished executing.
...@@ -397,7 +397,7 @@ used in a way that ensures they are always cleaned up promptly and correctly. :: ...@@ -397,7 +397,7 @@ used in a way that ensures they are always cleaned up promptly and correctly. ::
with open("myfile.txt") as f: with open("myfile.txt") as f:
for line in f: for line in f:
print(line) print(line, end="")
After the statement is executed, the file *f* is always closed, even if a After the statement is executed, the file *f* is always closed, even if a
problem was encountered while processing the lines. Objects which, like files, problem was encountered while processing the lines. Objects which, like files,
......
...@@ -592,6 +592,7 @@ Cédric Krier ...@@ -592,6 +592,7 @@ Cédric Krier
Hannu Krosing Hannu Krosing
Andrej Krpic Andrej Krpic
Ivan Krstić Ivan Krstić
Steven Kryskalla
Andrew Kuchling Andrew Kuchling
Dave Kuhlman Dave Kuhlman
Vladimir Kushnir Vladimir Kushnir
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment