Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d9569fa

Browse files
committed
Drop double newlines printed in some file iteration examples.
Patch by Steven Kryskalla.
2 parents 0c1034f + a7129d3 commit d9569fa

2 files changed

Lines changed: 3 additions & 2 deletions

File tree

Doc/tutorial/errors.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ succeeded or failed. Look at the following example, which tries to open a file
387387
and print its contents to the screen. ::
388388

389389
for line in open("myfile.txt"):
390-
print(line)
390+
print(line, end="")
391391

392392
The problem with this code is that it leaves the file open for an indeterminate
393393
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. ::
397397

398398
with open("myfile.txt") as f:
399399
for line in f:
400-
print(line)
400+
print(line, end="")
401401

402402
After the statement is executed, the file *f* is always closed, even if a
403403
problem was encountered while processing the lines. Objects which, like files,

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -656,6 +656,7 @@ Pedro Kroger
656656
Hannu Krosing
657657
Andrej Krpic
658658
Ivan Krstić
659+
Steven Kryskalla
659660
Andrew Kuchling
660661
Dave Kuhlman
661662
Jon Kuhn

0 commit comments

Comments
 (0)