Enumerating vertices with their indices This code...

def objects_starting( s ):
    return[ obj for obj in bpy.data.objects if obj.name.startswith( s ) ]

def export_all( folder ):
    if not os.path.exists( folder ):
        os.makedirs( folder )

    # G E O M E T R Y (2 files)
    for obj in objects_starting( 'geom' ):
        print( obj.name )
        verts_file = create_file( folder, obj.name + "_verts" )
        faces_file = create_file( folder, obj.name + "_faces" )

        export_geom( verts_file, faces_file, obj )

        verts_file.close( )
        faces_file.close( )

def export_geom( verts_file, faces_file, obj ):

    mesh = obj.data

    verts_file.write( "[points]\n" )
    verts_file.write( "%i\n" % len( mesh.vertices ) )

    for v in mesh.vertices:
        v_world = obj.matrix_world * v.co
        verts_file.write( "%i " % (v+1) )   &lt;-- FAILS HERE
        verts_file.write( "%.16e %.16e %.16e\n" % v_world[:] )


fails with:


  TypeError: %i format: a number is required, not MeshVertex


I'm scratching my head because I had something similar working yesterday:

def write(filepath):

    meshes = [ob.data for ob in bpy.context.selected_objects if ob.type == 'MESH']
    total_verts = sum(len(me.vertices) for me in meshes)
    total_faces = sum(len(me.polygons) for me in meshes)

    # verts file
    file = open(filepath + ".vert", 'w', encoding="utf8" )

    file.write("[nodes]\n")
    file.write("%i\n" % total_verts)

    for me in meshes:
        for v in me.vertices:
            file.write("%i " % v)
            file.write("%.16e %.16e %.16e\n" % v.co[:])
    file.close()


What is going on?  It must be that my new technique for getting a list of meshes doesn't return the right data type, or something.  But I can't see it.
What you try is:

verts_file.write("%i " % (v + 1))


But v refers to a MeshVertex instance. What you need is the .index property of the vertex:

verts_file.write("%i " % (v.index + 1))


Or count yourself:

for me in meshes:
    for i, v in enumerate(me.vertices):
        print("%i " % i)
        print("%.16e %.16e %.16e\n" % v.co[:])