append to a file

Thomas Wouters thomas at
Mon May 22 22:25:06 CEST 2000

On Mon, May 22, 2000 at 08:18:39PM +0000, Scott Hathaway wrote:

> How do I append to a file instead of overwriting it?  I searched on the
> python website and got a hit, but the link was bad.

Opening in 'append' mode, by passing 'a' as the 'how' flag to open:

file = open("my_file", "a")

Here's how you can find out:
>>> print open.__doc__
open(filename[, mode[, buffering]]) -> file object

Open a file.  The mode can be 'r', 'w' or 'a' for reading (default),
writing or appending.  The file will be created if it doesn't exist
when opened for writing or appending; it will be truncated when
opened for writing.  Add a 'b' to the mode for binary files.
Add a '+' to the mode to allow simultaneous reading and writing.
If the buffering argument is given, 0 means unbuffered, 1 means line
buffered, and larger numbers specify the buffer size.

Or you can use the Library reference for open(), at

Thomas Wouters <thomas at>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

More information about the Python-list mailing list