79525509

Date: 2025-03-21 13:01:08
Score: 2.5
Natty:
Report link

You make assumptions about how the file is read and where the write seek position is. Mode "r+" supports write-after-seek, however, you have to explicitly seek to that position.

with open('test.txt','r+') as f:
  f.seek(f.tell())
  f.write("wow!")
  f.flush()

test.txt now contains:

Helwow!orld!

See also Difference between modes a, a+, w, w+, and r+ in built-in open function?

Reasons:
  • Low length (0.5):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • Low reputation (0.5):
Posted by: André