[Tutor] Outputting to text files

Remco Gerlich scarblac@pino.selwerd.nl
Sun, 20 Aug 2000 21:11:25 +0200

On Sun, Aug 20, 2000 at 06:49:13PM +0000, isopod graphics wrote:
>    It's been a while since I asked a question(about a week now!he he he!. 
> Now I've stumbled to another problem that I'm sure other have easily 
> avoided; here it goes: I'm writing a program that does some math 
> calculations like slope calculaion etc., now I wanna save or output the 
> results to a text file.How do I go about doing that?

Similar to reading from a file, except you open the file for "w" (write)
instead of "r" (read):

f = open("menu","w")
f.write("spam, spam, spam and eggs\n")
f.write("spam, eggs, spam, spam, bacon and spam\n")

You can also open it "a" to append to a file (if you open for write, the
first thing that happens is that the old file is emptied, if it exists).

> Another one (sorry about this very simple Algebra 
> question) how do you compute the y-intercept if you were just given the 
> coordinates of 2 points (x1,y1 and x2,y2)?

I'm not sure what the y-intercept is. You mean the point in the middle of
those two? That's just the average point, ie ((x1+x2)/2, (y1+y2)/2).

Remco Gerlich,  scarblac@pino.selwerd.nl