[Tutor] Adding Text to the Beginning of a File
Jeff Shannon
jeff at ccvcorp.com
Fri Nov 5 22:09:15 CET 2004
Alan Colburn wrote:
> Hi all --
>
> Can anyone offer me a suggestion for how to add text
> to the beginning of a file? I know that file.seek(0)
> takes me to the beginning of the file, but
> file.write() ultimately still adds new strings to the
> end of the file. (The file is opened in a+ mode...)
Even if you did get write() to start writing at the beginning of the
file, it would (as I understand it) simply overwrite the existing data.
AFAIK, the only good way to add text to the beginning of a file is to
read the entire file in, make modifications to the text in-memory, and
then write the entire file out again (presumably to the same filename).
Jeff Shannon
Technician/Programmer
Credit International
More information about the Tutor
mailing list