functionsscopingand abstraction we can now open the file for reading (using the argument ' ')and print its contents since python treats file as sequence of lineswe can use for statement to iterate over the file' contents namehandle open('kids'' 'for line in namehandleprint line namehandle close(if we had typed in the names david and andreathis will print david andrea the extra line between david and andrea is there because print starts new line each time it encounters the '\nat the end of each line in the file we could have avoided printing that by writing print line[:- now consider namehandle open('kids'' 'namehandle write('michael\ 'namehandle write('mark\ 'namehandle close(namehandle open('kids'' 'for line in namehandleprint line[:- namehandle close(it will print michael mark notice that we have overwritten the previous contents of the file kids if we don' want to do that we can open the file for appending (instead of writingby using the argument 'afor exampleif we now run the code namehandle open('kids'' 'namehandle write('david\ 'namehandle write('andrea\ 'namehandle close(namehandle open('kids'' 'for line in namehandleprint line[:- namehandle close(it will print michael mark david andrea