fp.flush()
file_length = fp.tell()
mm = mmap.mmap(fp.fileno(), file_length)
bytes_to_shift = file_length - offset - len(some_bytes)
mm.move(offset + len(some_bytes), offset, bytes_to_shift)
mm[offset:offset + len(some_bytes)] = some_bytes
mm.close()
if __name__ == '__main__':
    with open('test.txt', 'w') as fp:
        fp.write('Hello, World!')
with open('test.txt', 'r+b') as fp:
    insert_string(fp, 6, ' funny')
вставка строки в большой файл