Faqts : Business : Programming : Shopping For You : Python : Common Problems : Files

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

45 of 49 people (92%) answered Yes
Recently 9 of 10 people (90%) answered Yes

Entry

How do I append to a file instead of overwriting it?

May 24th, 2000 07:04
unknown unknown, Emile van Sebille, Thomas Wouters


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 
http://www.python.org/doc/lib/