I'm trying to read from an originally empty file, after a write, before closing it. Is this possible in Python?
with open("outfile1.txt", 'r+') as f:
f.write("foobar")
f.flush()
print("File contents:", f.read())
Flushing with f.flush()
doesn't seem to work, as the final f.read()
still returns nothing.
Is there any way to read the "foobar" from the file besides re-opening it?