I know, w+ means both read and write, then I write this code to read some message from a txt file and write some message into it
This is my code:
f = open('test', 'w+')
f.write('yes yes yes\n')
print f.read()
......
f.close()
when i run it, It only print newline, and didn't print yes yes yes
then I open test file, I found yes yes yeswas in it!
Why it' just print new line, but print yes, and what's the difference between w+ & r+
You should put cursor at the beginning of file before reading.
f.seek(0)
f.read()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With