Is it possible to read and write simultaneously to the same file? I have this chunk of code:
with open(total_f, 'w') as f:
s= len(resu)
#print s
f.write ("the total number is {}\n".format(s))
f.write('\n'.join(map(str, resu)))
with open(total_f ,'r') as f:
content = f.read()
count = content.count("FFFF")
print count
but I need them to be together, because I want to write the result of count
in total_f
.
I tried to put in the read/write together like this:
with open(total_f, 'rw') as f:# i want to read and write at the same time
s= len(resu)
content = f.read()
count = content.count("FFFF")
#print s
f.write ("the total number is {}\n".format(s))
f.write ("the total number is {}\n".format(count))
f.write('\n'.join(map(str, resu)))
But it's still not working, and so I'm not sure if that's correct.