[Tutor] text files
Alan Gauld
alan.gauld at btinternet.com
Wed Jan 16 12:38:45 CET 2013
On 16/01/13 02:31, Gina wrote:
> new_file = open("the_file_upper.txt", "w+")
In general consider the w+ file option to be for advanced use only.
Either open it for reading or writing, don't try to do both at the same
time. It's a bit like sitting on a tree branch with a saw to cut it
down. If you cut on the wrong side you get hurt...
> new_file.write(*****)
> print(new_file.read())
This won't read anything because the file cursor is at the end of the
string that you wrote (remember the branch illustration?)
> new_file.close()
And this just closes the file with a short line of asterisks in it...
Not really what you want.
--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
More information about the Tutor
mailing list