I want to open a file, load the content, and then write new content into this file to overwrite everything in the file. I tested but it didn't work as expected:
handler = open('test.txt', 'w+')
for line in handler:
print(line)
It prints out nothing. It seems 'w+' wipes output everything in the first place, but according to documentation:
Write and Read (‘w+’) : Open the file for reading and writing. For an existing file, data is truncated and over-written. The handle is positioned at the beginning of the file.
What's the issue?