My understanding of the the documentation is that w writes and truncates first while + updates (reads and writes):
f=open("/tmp/f",mode="tw+")
f.write("foo\nbar")
f.readlines() #returns empty list? What am I missing?
https://docs.python.org/3/library/functions.html#open
>Solution :
Mode r+ will read/write without truncating and w+ will read/write with truncating first.
What you’re missing is the fact that after writing, your file position is at the end of the file. If you’ll use f.seek(0) after writing, you’ll be able to read just fine.