How do I create a text datablock and populate it with text with Python?
Sample code creating text block and populating with scene info.

import bpy

obj = bpy.context.object # select active object

if obj:
    ntxt = bpy.data.texts.new(obj.name)
    ntxt.write("Name: %s \n" % obj.name)
    ntxt.write("Location: %s \n" % obj.location)
    if obj.type == 'MESH':
        ntxt.write("Vertices: \n")
        verts = [v.co for v in obj.data.vertices]
        for v in verts:
            ntxt.write("\t %s \n" %v)

classes = []


def register():
    for cls in classes:
        bpy.utils.register_class(cls)


def unregister():
    for cls in classes:
        bpy.utils.unregister_class(cls)

if __name__ == "__main__":
    register()