CSCA08H3 Final: CSCA08_SummaryForFinal.docx

136 views12 pages

Document Summary

Our data files are text files which are filled with characters. In python, we must open files before we can use them and close them when we are done with them. Once a file is opened, it becomes a python object just like all other data. A line of a file is defined to be a sequence of characters up to and including a special character called the newline character (\n). My examples nothing more to say open(filename, r"): open a file called filename and use it for reading. open(filename, w"): open a file called filename and use it for writing. open() will return a reference to a file object. #if the file and the python program are in the same directory open( test. txt", r") #create a variable name for later referencing my_file = open( test. txt", r") Reads and returns a string of n characters, or the entire file as a single string if n is not provided.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers

Related Documents

Related Questions