Read the contents of a Text Datablock Writing into a text datablock can be done with the script

text = bpy.data.texts[name]
text.write(something)


However, when I used the script text.read, an error appeared.

Question: How do I read the content in a text datablock with a script?
I have never needed to work with text blocks so I have no idea yet. Let's find out.

If you press Tab after writing something in the Python Console, you can see all the available options from auto complete like this:



We can see that it is possible to access lines text.lines so if we want to read the 4th line for example we carry on with auto complete:



and see that it has body, that's probably the thing we need here then:



It's a string. That's it.