Editing text data block using Python

Is it possible to modify the content of a text data block in the text editor using Python? I have 100 blocks of text data and would like to replace parts of their code in bulk or rename variables.