Appending/inserting in outfile.write()
effbot at telia.com
Mon Feb 28 22:19:40 CET 2000
Will <wcohen at interpath.com> wrote:
> I'm trying to write a CGI Python guestbook. Would there be a way for me
> to get the script to simply append, say 14 bytes from the end, to the
> HTML guestbook file rather than completely overwriting it and holding
> only one entry? I can use outfile.write to simply rewrite the entire
> file. Do I need to use another function or just set a flag? If I can't
> insert text, can i just delete the last 14 bytes and rewrite the end
> from there?
you cannot insert or delete data from files,
but overwriting things is easy:
fp = open(filename, "r+")
fp.write("add to the end of the file")
for more info, see the docs.
hope this helps!
More information about the Python-list