09_3_read_and_write-1 - Reading and writing files...

Info iconThis preview shows pages 1–2. Sign up to view the full content.

View Full Document Right Arrow Icon
# Reading and writing files. .. # readAndPrint reads the contents of a text file and prints it out # to command area # # Note the dot notation. read and close are methods, not functions. def readAndPrint(filename): inConnection = open(filename, "rt") text = inConnection.read() print "The text is. ..", text inConnection.close() # inputAndWrite gets some text from a user and then writes it out to file def inputAndWrite(filename): text = requestString("Type some text that you want to save into a file") outConnection = open(filename, "wt") outConnection.write(text) outConnection.close() # readAndWrite makes a copy of a text file named "temp.bak" in the same # folder as the original. def readAndWrite(filename): inConnection = open(filename, "rt") text = inConnection.read() inConnection.close() outConnection = open(getPath(filename)+"temp.bak", "wt") outConnection.write(text) outConnection.close() # downloadAndPrint is like readAndPrint but works for a web address, # not a local file name def downloadAndPrint(url):
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This document was uploaded on 10/27/2011 for the course CS 1315 at Georgia Tech.

Page1 / 2

09_3_read_and_write-1 - Reading and writing files...

This preview shows document pages 1 - 2. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online