Open
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.)