to read file' contentscall read(size)which reads some quantity of data and returns it as string (in text modeor bytes object (in binary modesize is an optional numeric argument when size is omitted or negativethe entire contents of the file will be read and returnedit' your problem if the file is twice as large as your machine' memory otherwiseat most size bytes are read and returned if the end of the file has been reachedf read(will return an empty string ('' read('this is the entire file \nf read(' readline(reads single line from the filea newline character (\nis left at the end of the stringand is only omitted on the last line of the file if the file doesn' end in newline this makes the return value unambiguousif readline(returns an empty stringthe end of the file has been reachedwhile blank line is represented by '\ ' string containing only single newline readline('this is the first line of the file \nf readline('second line of the file\nf readline('for reading lines from fileyou can loop over the file object this is memory efficientfastand leads to simple codefor line in fprint(lineend=''this is the first line of the file second line of the file if you want to read all the lines of file in list you can also use list(for readlines( write(stringwrites the contents of string to the filereturning the number of characters written write('this is test\ ' other types of objects need to be converted either to string (in text modeor bytes object (in binary modebefore writing themvalue ('the answer' str(valueconvert the tuple to string write( tell(returns an integer giving the file object' current position in the file represented as number of bytes from the beginning of the file when in binary mode and an opaque number when in text mode to change the file object' positionuse seek(offsetfrom_whatthe position is computed from adding offset to reference pointthe reference point is selected by the from_what argument from_what value of measures from the beginning of the file uses the current file positionand uses the end of the file as the reference point from_what can be omitted and defaults to using the beginning of the file as the reference point open('workfile''rb+' write( ' abcdef'(continues on next page input and output