this is private supporting method used by some of the other methods to move the file position pointer to the first byte of the record at the given index position we begin by checking to see whether the given index is in range we do this by seeking to the end of the file (byte offset of from the end)and using the tell(method to retrieve the byte position we have seeked to if the record' offset (index position real record sizeis at or after the end then the index is out of range and we raise suitable exception otherwisewe seek to the offset position ready for the next read or write def __delitem__(selfindex)self __seek_to_index(indexstate self __fh read( if state !_okayreturn self __fh seek(index self __record_sizeself __fh write(_deletedif self auto_flushself __fh flush(first we move the file position pointer to the right place if the index is in range ( if no indexerror exception has occurred)and providing the record isn' blank or already deletedwe delete the record by overwriting its state byte with _deleted def undelete(selfindex)self __seek_to_index(indexstate self __fh read( if state =_deletedself __fh seek(index self __record_sizeself __fh write(_okayif self auto_flushself __fh flush(return true return false this method begins by finding the record and reading its state byte if the record is deleted we overwrite the state byte with _okay and return true to the caller to indicate successotherwise (for blank or nondeleted records)we return false def __len__(self)if self auto_flushself __fh flush(self __fh seek( os seek_endboth python and have the seek constants os seek_setos seek_curand os seek_end for conveniencepython also has these constants in its io module ( io seek_set