When executing the following code, after the second read, file gets filled with zero until being 4096 bytes large. I can’t figure out why :
f = open("file.txt", "w+")
f.read()
# gives ''
f.write("Hello")
f.read()
# filled with \x00,\x00
f.close()
# file is 4096 bytes large...
Best way to solve your problem: don’t mix
read()andwrite().Otherwise: after the
write(), useseek()before the secondread()to read your file from the beginning: