Print vertex coordinates and vertex weights

Hi guys does anyone know how to make a script for Blender to print on a text file or on the blender shell, vertex coordinates and their weights for a given selecton of vertexes in edit mode? Thanks. The purpose is to have printed informations about vertex groups.

bpy.ops.object.mode_set(mode='OBJECT') # needed so vertex.select is set correctly
for v in list(filter(lambda v: v.select, bpy.context.active_object.data.vertices)):
    for e in v.groups:
        print(f"Vertex {v.index} has weight {e.weight} in vertex group {bpy.context.active_object.vertex_groups[e.group].name}.")

Thanks for your help.I tested it, the shell said bpy not defined

What do you mean by this? The code needs to go here:

Oh thanks i used It in the script section of blender