WRITING FILES
Carsten Gaebler
cg at schlund.de
Thu Oct 19 09:55:39 EDT 2000
Sergio Boix Moriano wrote:
>
> Hi all,
>
> I want to make a procedure to append lines to a file, in the
> position i want.
>
> I've tried to do this opening the file in mode "r+", but if i do
> this, it writes in the document from a position x, but overwritting the
> text that is in the document. If i open de document with (a+) it writes
> always at the end of the document.
>
> What i'm doing bad?
To insert data into a file at a certain position x, you'll have to
create a temporary file, copy all data from the original file up to that
position x to the temporary file, write the new data to the temporary
file, copy all original data after position x to the temporary file,
remove the original file and rename the temporary file to the original
file name.
cg.
More information about the Python-list
mailing list