code: def replaceText(self, pos, length, text):
          
          if isinstance(pos, tuple):
              pos = self.mapToAbsPosition(*pos)
  
          endPos = pos + length
  
          if not self.document().findBlock(pos).isValid():
              raise IndexError('Invalid start position %d' % pos)
  
          if not self.document().findBlock(endPos).isValid():
              raise IndexError('Invalid end position %d' % endPos)
  
          cursor = QTextCursor(self.document())
          cursor.setPosition(pos)
          cursor.setPosition(endPos, QTextCursor.KeepAnchor)
  
          cursor.insertText(text)
docs: Replace length symbols from ``pos`` with new text.
  
          If ``pos`` is an integer, it is interpreted as absolute position, if a tuple - as ``(line, column)``