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

Skip to content

Commit 09974b4

Browse files
committed
Drop double newlines printed in some file iteration examples.
Patch by Steven Kryskalla.
1 parent 5a2e2b8 commit 09974b4

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
@@ -592,6 +592,7 @@ Cédric Krier
592592
Hannu Krosing
593593
Andrej Krpic
594594
Ivan Krstić
595+
Steven Kryskalla
595596
Andrew Kuchling
596597
Dave Kuhlman
597598
Vladimir Kushnir

0 commit comments

Comments
 (0)