Writing to a text file: write()

write() writes a string to a file

The program:

# open, write to, and close the file
aFile = file("out.txt", "w")
aFile.write("first line\nsecond line")
aFile.close()

# open, read from, and close the file
aFile = file("out.txt", "r")
print aFile.read()
aFile.close()

prints:

first line
second line