How to write a simple Wavefront-OBJ exporter in Python?
This is a simple OBJ export script, that this writes valid OBJ files that load back into Blender: verts and faces, (no edges or materials).

import bpy
from bpy import context

filepath = "/tmp/simple_obj.obj"

obj = context.object
mesh = obj.data

with open(filepath, 'w') as f:
    f.write("# OBJ file\n")
    for v in mesh.vertices:
        f.write("v %.4f %.4f %.4f\n" % v.co[:])
    for p in mesh.polygons:
        f.write("f")
        for i in p.vertices:
            f.write(" %d" % (i + 1))
        f.write("\n")




This script can be pasted into Blenders text editor and executed, you will want to modify the output filepath.