CS 1315 Lecture 1: FileIOBasics

27 views2 pages

Document Summary

Reading in a file- rt or r . Writing to a file- adding something, w . File pipe (aka connection/stream)- how code is connected to a file; filestream = open (must be closed eventually) Method- command; what is after the dot. Picture example: what we"re used to pic = makeemptypicture(11,11) pix1 = getpixel(pic,1,1) r1 = getred(pix1) print "pix1", pix1 print "pix1 red", r1. Picture example: dot notation pic = makeemptypicture(11,11) pix1 = pic. getpixel(1,1) r1 = pix1. getred() print "pix1", pix1 print "pix1 red", r1. Give some examples of dot notation applied to strings (you learned some of these in recitation): Template for reading all contents from a file. Step description: determine. filename(file = pickafile(), parameter, open stream to the file, read contents from file, close the stream. Need to create filestream first) filestream = open(cid:523)filename, (cid:498)rt(cid:499)(cid:524) (cid:523)you can"t do filestream. open because there"s no. Contents = filestream. readlines(cid:523)(cid:524) a list of strings, one string per line filestream. close()

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
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers