print number and index of selected lines in text editor I try to improve my "comment", uncomment", "copy" and "cut" command in the text editor and i'd like to know if it was possible to print the number and the index of selected lines in the text editor.
I'd like to comment or uncomment all selected lines.
This is the code i'm using to comment:

class CustomComment(bpy.types.Operator):
    ''' Auto comment with a space after # '''
    bl_idname = "text.custom_comment"
    bl_label = "Custom comment"

    def execute(self, context):

        base = context.space_data.text.current_line.body
        bpy.ops.text.select_line()            
        if "    " in base:
            bpy.ops.text.move(type='LINE_BEGIN')
            bpy.ops.text.move(type='NEXT_WORD')        
            bpy.ops.text.insert(text="# ")
        else:
            bpy.ops.text.move(type='LINE_BEGIN')        
            bpy.ops.text.insert(text="# ")                
        return {'FINISHED'}
import bpy

txt = bpy.data.texts['Text']
line_begin = txt.current_line_index

#select_end_line_index missing - iterate over txt.lines
for line_end, line_obj in enumerate(txt.lines):
    if line_obj == txt.select_end_line:
        break

selection = [i for i in range(line_begin, line_end + 1)]
print(selection)


There is already a comment function