[Tutor] file overwrite

Gregor Lingl glingl@aon.at
Wed, 2 Jan 2002 10:28:24 +0100


In the Python-Tutorial we find at
http://www.python.org/doc/current/tut/node9.html#SECTION00920000000000000000
0

7.2 Reading and Writing Files

open() returns a file object , and is most commonly used with two arguments:
"open(filename, mode)".

>>> f=open('/tmp/workfile', 'w')
>>> print f
<open file '/tmp/workfile', mode 'w' at 80a0960>

The first argument is a string containing the filename. The second argument
is another string containing a few characters describing the way in which
the file will be used. mode can be 'r' when the file will only be read, 'w'
for only writing (an existing file with the same name will be erased), and
'a' opens the file for appending; any data written to the file is
automatically added to the end. ...

------

So use:

f1=open('./lists/pending','a')

instead of

f1=open('./lists/pending','w')

if this was the line that bothered you.

Gregor

...

> # keep that above line blank!
> subject = command + " " + listname + " " + timestamp
> f1=open('./lists/pending','w')          # open the pending file
> f1.write(subject+"\n")                  # write the entire stubject string
into it
> f1.close()                              # and close the file.