CS 110 Study Guide - Midterm Guide: Gnu Readline, Opentext, Newline

109 views5 pages

Document Summary

There are two methods to open text files: open(filename, r") opens a file called filename for reading only. open(filename, w") opens a file called filename for writing only. If you are reading a file and want to edit it, you must close it and reopen it for writing: filevariable. close() closes the file for use. Given a file qbdata. txt , you open the file for reading by: fileref = open( qbdata. txt , r") After you"re done reading the file, you close the reference to it: fileref. close() Once a file is opened, it is treated as one long string, with separate lines. A line of a file is a sequence of characters up to and including the newline character \n. \n represents pressing the enter or return key in a program. The split method breaks each line into a list of every value in the line separated by spaces: newlist = line. split()

Get access

Grade+
$40 USD/m
Billed monthly
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
10 Verified Answers

Related Documents

Related Questions