-
-
Notifications
You must be signed in to change notification settings - Fork 33.3k
Open
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
The following produces a file containing b'hello\n ', i.e. hello followed by a newline and a space:
with open("asd.txt", "w") as file:
file.write("hello\n")
with open("asd.txt", "r+") as file:
file.read(4)
file.write(" ")But if I add file.seek(file.tell()), then it instead produces b'hell \n' as I would expect:
with open("asd.txt", "w") as file:
file.write("hello\n")
with open("asd.txt", "r+") as file:
file.read(4)
file.seek(file.tell())
file.write(" ")Is this correct behaviour? I can't find any mention of it in the docs. (I can't use file.seek(4) because that "produces undefined behaviour" according to docs.)
mguinhos
Metadata
Metadata
Assignees
Labels
interpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)topic-IOtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error