Week 8, more Top-Down Design

dino image

File OUTPUT:

Here's how to open a file for writing (note: myfile is a variable name that I choose, and "newfile" is the name of the file to write to):

$ python
>>> myfile = open("newfile", 'w')
>>> type(myfile)
<type 'file'>
>>> myfile.write("write this to the file \n")
>>> myfile.write("and this.... \n")
>>> myfile.close()

and here are the results of this:

$ ls
newfile
$ cat newfile
write this to the file
and this....

What happens if we leave out the \n on each line??