mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Drop double newlines printed in some file iteration examples.
Patch by Steven Kryskalla.
This commit is contained in:
commit
d9569fa90d
2 changed files with 3 additions and 2 deletions
|
@ -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. ::
|
||||
|
||||
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
|
||||
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. ::
|
|||
|
||||
with open("myfile.txt") as f:
|
||||
for line in f:
|
||||
print(line)
|
||||
print(line, end="")
|
||||
|
||||
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,
|
||||
|
|
|
@ -656,6 +656,7 @@ Pedro Kroger
|
|||
Hannu Krosing
|
||||
Andrej Krpic
|
||||
Ivan Krstić
|
||||
Steven Kryskalla
|
||||
Andrew Kuchling
|
||||
Dave Kuhlman
|
||||
Jon Kuhn
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue