[Tutor] Append To File

Jason Drake jdrake@jam.rr.com
Sat, 24 Feb 2001 15:52:19 -0600


This is a multi-part message in MIME format.

------=_NextPart_000_0010_01C09E79.C49367C0
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Okay, first I will admit that I'm still digesting Danny Yoo's advice re: =
string interpolation. I will make attempts to use the technique he =
outlined some time today. What I'm up against right now has to do with =
appending to a file. My current code reads as follows:

#!/usr/bin/python
# append.cgi
# Author: Frik -- www.lowerstandard.com
# append data to a file, then print the data to screen
#

output =3D "no"

print "Content-type: text/html\n"

###
file =3D open('testdb.txt', 'w')
file.write(output)
###
print output
###

Although simple, this does exactly what I want it to do at this stage =
except for one little detail. If I hit this cgi it will write 'no' to my =
text file as it is supposed to, but I want to write to a new line rather =
than on the same line directly after the first. At present my text file =
which is being appended to reads=20

nonononono

What I want it to read as is

no
no
no
no
no

The obvious question, how do I write to a new line in an opened file?

TIA

Jay D

------=_NextPart_000_0010_01C09E79.C49367C0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 5.50.4611.1300" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>Okay, first I will admit that I'm still =
digesting=20
Danny Yoo's advice re: string interpolation. I will make attempts to use =
the=20
technique he outlined some time today. What I'm up against right now has =
to do=20
with appending to a file. My current code reads as follows:</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>#!/usr/bin/python<BR># append.cgi<BR># =
Author: Frik=20
-- <A =
href=3D"http://www.lowerstandard.com">www.lowerstandard.com</A><BR># =
append=20
data to a file, then print the data to screen<BR>#</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>output =3D "no"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>print "Content-type: =
text/html\n"</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>###<BR>file =3D open('testdb.txt',=20
'w')<BR>file.write(output)<BR>###<BR>print output<BR>###</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Although simple, this does exactly what =
I want it=20
to do at this stage except for one little detail. If I hit this cgi it =
will=20
write 'no' to my text file as it is supposed to, but I want to write to =
a new=20
line rather than on the same line directly after the first. At present =
my text=20
file which is being appended to reads </FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>nonononono</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>What I want it to read as =
is</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2>no</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>The obvious question, how do I write to =
a new line=20
in an opened file?</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>TIA</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Jay D</FONT></DIV></BODY></HTML>

------=_NextPart_000_0010_01C09E79.C49367C0--