Having trouble with file modes
martdi
martin.dion at gmail.com
Fri Nov 3 16:00:13 EST 2006
> At first I was convinced that "w+" was the tool for the job. But now
> I'm finding that the contents of the file are deleted (so I can't read
> the data in).
Possible File Modes:
a : Append -- Add data at the end of the file
r : Read -- Read from the file
w : write -- Flush contents of the file and put data in it
r+ : read and write -- Make changes to the file
any of the above modes with b added at the end of the mode sets the
file in binary mode
you might want to check section 7.2 from
http://docs.python.org/tut/node9.html
Ofen when doing file operations you might prefer to read the file to
modify, make changes in memory then save back in an other file, so you
can make sure the changes are ok before you replace the old one
More information about the Python-list
mailing list