How to add lines to the beginning of a text file?

Jon Clements joncle at googlemail.com
Fri Apr 3 21:50:22 EDT 2009


On 4 Apr, 02:21, dean <de... at yahoo.com> wrote:
> Hello,
>
> As the subject says how would I go about adding the lines to the beginning
> of a text file? Thanks in advance.

I'd create a new file, then write your new lines, then iterate the
existing file and write those lines... If no errors occcur, issue a
delete for the old file, and a rename for new file to the old name.

hth

Jon.



More information about the Python-list mailing list