code: def write_idx(self, idx, buf):
          
          key = self.key_type(idx)
          pos = self.tell()
          self.write(buf)
          self.fidx.write('%s\t%d\n'%(str(key), pos))
          self.idx[key] = pos
          self.keys.append(key)
docs: Inserts input record at given index.
  
          Examples
          ---------
          >>> for i in range(5):
          ...     record.write_idx(i, 'record_%d'%i)
          >>> record.close()
  
          Parameters
          ----------
          idx : int
              Index of a file.
          buf :
              Record to write.