Week_13_file_IO - dataout.write(“Some text n”...

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

View Full Document Right Arrow Icon
CMPT120 J. Ye File Output and Input (Week 13) File output File input CMPT120 J. Ye Manipulate information in the computer’s memory vs. Manipulate information in a file A file is a named sequence of bits that is stored on an external storage device, such as a hard drive, a USB key, a CD, etc. A text file stores a sequence of characters and can be edited with a text editor. 2 Text Files
Background image of page 1

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

View Full DocumentRight Arrow Icon
CMPT120 J. Ye Sending information to screen vs. sending information to files Writing data to a text file: dataout = file(“sample.txt”, “w”) (or: dataout = open(“sample.txt”, “w”)
Background image of page 2
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: ) dataout.write(“Some text \ n”) dataout.write(“…that is written to a file \ n”) dataout.close() (See writing_file.py for explanation about the above statements.) • Test the code in Figure 7.3 in the Study Guide (Page 149) 3 Writing to files • We can also read data from an existing file: datain = file(“sample.txt”, “r”) (or: datain = open(“sample.txt”, “r”) ) data = datain.read() # read() returns entire file as a string print(data) datain.close() • Test the above code 4 Reading from files...
View Full Document

This note was uploaded on 08/28/2011 for the course CMPT 125 taught by Professor Diana during the Spring '08 term at Simon Fraser.

Page1 / 2

Week_13_file_IO - dataout.write(“Some text n”...

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