file handling end self __fh tell(return end /self __record_size this method reports how many records are in the binary record file it does this by dividing the end byte position ( how many bytes are in the fileby the size of record we have now covered all the basic functionality offered by the binaryrecordfile binaryrecordfile class there is one last matter to considercompacting the file to eliminate blank and deleted records there are essentially two approaches we can take to this one approach is to overwrite blank or deleted records with records that have higher record index positions so that there are no gapsand truncating the file if there are any blank or deleted records at the end the inplace_compact(method does this the other approach is to copy the nonblank nondeleted records to temporary file and then to rename the temporary to the original using temporary file is particularly convenient if we also want to make backup the compact(method does this we will start by looking at the inplace_compact(methodin two parts def inplace_compact(self)index length len(selfwhile index lengthself __seek_to_index(indexstate self __fh read( if state !_okayfor next in range(index length)self __seek_to_index(nextstate self __fh read( if state =_okayself[indexself[nextdel self[nextbreak elsebreak index + we iterate over every recordreading the state of each one in turn if we find blank or deleted record we look for the next nonblank nondeleted record in the file if we find one we replace the blank or deleted record with the nonblank nondeleted one and delete the original nonblank nondeleted oneotherwisewe break out of the while loop entirely since we have run out of nonblank nondeleted records self __seek_to_index( state self __fh read(