Mesh gets out of sync while in edit-mode (Python)
In edit-mode, the mesh as defined by bpy.types.Mesh is not used, there is in fact a different mesh-representation being used (bmesh.types.BMesh), which supports editing operations and modifications.

So changes to bpy.context.object.data are not displayed, and they will be overwritten when exiting editmode.

Instead, you have to access the BMesh.

import bpy
import bmesh

obj = bpy.context.edit_object
me = obj.data

# Get a BMesh representation
bm = bmesh.from_edit_mesh(me)


Once you have a bmesh from the edit-mesh, you are directly accessing the same data which the user is manipulating.

For the full example, see:


  Text Editor -> Templates -> Python -> BMesh Simple Editmode


See BMesh API docs:
http://www.blender.org/api/blender_python_api_2_72_release/bmesh.html