How do I select specific vertices in blender using python script? I have created a plane and have applied loop cut and slide twice horizontally and once vertically( using python script). 

With this done, I intend to select the top two corner vertices using python script.

The image of the model can be viewed in the following link,



I browsed through net and found a code for selecting faces. So I figured, I would try the same with vertices. The code snippet is below,

bpy.ops.object.mode_set(mode = 'OBJECT')
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT') 
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.mesh.select_all(action = 'DESELECT')
obj.data.vertices[0].select = True # I TRIED THIS WITH ALL VALUES LIKE 0,1..


But, the result though no error did not give me the expected output.All Vertices remain unselected. 

Please help me with solving this.
This is probably counter-intuitive but you should place the Object in OBJECT mode when doing selection using indices via Python. Then flip back to EDIT mode to see the result.

import bpy

bpy.ops.object.mode_set(mode = 'OBJECT')
obj = bpy.context.active_object
bpy.ops.object.mode_set(mode = 'EDIT') 
bpy.ops.mesh.select_mode(type="VERT")
bpy.ops.mesh.select_all(action = 'DESELECT')
bpy.ops.object.mode_set(mode = 'OBJECT')
obj.data.vertices[0].select = True
bpy.ops.object.mode_set(mode = 'EDIT') 


Another way to make selections is to use BMesh, you'll find templates for this in
TextEditor -> Templates -> Python -> Simple Bmesh (edit mode)