'bye file world \nfile __next__(traceback (most recent call last)file ""line in stopiteration interestinglyiterators are automatically used in all iteration contextsincluding the list constructor calllist comprehension expressionsmap callsand in membership checksopen('data txt'readlines(['hello file world!\ ''bye file world \ 'always read lines list(open('data txt')['hello file world!\ ''bye force line iteration file world \ 'lines [line rstrip(for line in open('data txt')lines ['hello file world!''bye file world 'comprehension lines [line upper(for line in open('data txt')lines ['hello file world!\ ''bye file world \ 'arbitrary actions list(map(str splitopen('data txt'))[['hello''file''world!']['bye''file''world ']apply function line 'hello file world!\nline in open('data txt'true line membership iterators may seem somewhat implicit at first glancebut they're representative of the many ways that python makes developerslives easier over time other open options besides the and (defaultr file open modesmost platforms support an mode stringmeaning "append in this output modewrite methods add data to the end of the fileand the open call will not erase the current contents of the filefile open('data txt'' 'open in append modedoesn' erase file write('the life of brian'added at end of existing data file close(open('data txt'read(open and read entire file 'hello file world!\nbye file world \nthe life of brianin factalthough most files are opened using the sorts of calls we just ranopen actually supports additional arguments for more specific processing needsthe first three of which are the most commonly used--the filenamethe open modeand buffering specification all but the first of these are optionalif omittedthe open mode argument file and directory tools