when processing filethe proxy maintains current position within the file as an offset from the beginningmeasured in number of bytes when opening file with mode or the position is initially if opened in append modea the position is initially at the end of the file the syntax fp closecloses the file associated with proxy fpensuring that any written contents are saved summary of methods for reading and writing file is given in table calling syntax fp readfp read(kfp readlinefp readlinesfor line in fpfp seek(kfp tellfp write(stringfp writelines(seqprintfile=fpdescription return the (remainingcontents of readable file as string return the next bytes of readable file as string return (remainder of the current line of readable file as string return all (remaininglines of readable file as list of strings iterate all (remaininglines of readable file change the current position to be at the kth byte of the file return the current positionmeasured as byte-offset from the start write given string at current position of the writable file write each of the strings of the given sequence at the current position of the writable file this command does not insert any newlinesbeyond those that are embedded in the strings redirect output of print function to the file table behaviors for interacting with text file via file proxy (named fpreading from file the most basic command for reading via proxy is the read method when invoked on file proxy fpas fp read( )the command returns string representing the next bytes of the filestarting at the current position without parameterthe syntax fp readreturns the remaining contents of the file in entirety for conveniencefiles can be read line at timeusing the readline method to read one lineor the readlines method to return list of all remaining lines files also support the for-loop syntaxwith iteration being line by line ( for line in fp:writing to file when file proxy is writablefor exampleif created with access mode or text can be written using methods write or writelines for exampleif we define fp openresults txt )the syntax fp writehello world \ writes single line to the file with the given string note well that write does not explicitly add trailing newlineso desired newline characters must be embedded directly in the string parameter recall that the output of the print method can be redirected to file using keyword parameteras described in section