appending a file

Remco Gerlich scarblac-spamtrap at pino.selwerd.nl
Tue Mar 14 19:02:24 CET 2000


Lenny Self wrote in comp.lang.python:
> Hello.
> 
> I am a little frustrated. After looking all over the place ( Learning
> Python, the Python Pocket Reference, Library Reference) I have been unable
> to find how to append to the end of an existing text file using python in
> any way other than reading the entire contents of the file out to a list,
> adding the additional information, and then writing it all back to the
> original file.  I know there must  be a better way to do this; for the life
> of me, however, I seem to me unable to find it.
> 
> Can anyone help me out?

open(filename, 'a')

'a' for append. I'm sure it's in those books you named as well, but it's also
in the output of "print open.__doc__".

-- 
Remco Gerlich,  scarblac at pino.selwerd.nl

   This is no way to be
     Man ought to be free      -- Ted Bundy
       That man should be me



More information about the Python-list mailing list