Feb-16-2023, 02:05 PM
You could use fd.seek() to jump to the end of the file:
with open("file.txt", "w") as fd: for line in range(1, 5): fd.write(f"Welcome to Python line {line}\n") with open("file.txt", "r+") as fd: print("Position after open:", fd.tell()) fd.seek(0, 2) print("Position after seek:", fd.tell()) fd.write("Hello World\n") with open("file.txt", "r") as fd: print(fd.read())Docs: https://docs.python.org/3/library/io.htm...OBase.seek
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
All humans together. We don't need politicians!