# Select vertices of mesh in python

What is the python way to select vertices of a mesh?

I've tried:

for vert in obj.data.vertices:
vert.select = True


I ran the above code in edit mode, but the vertices didn't turn yellow.

• – Knuckles209cp Jan 13 '15 at 5:22

import bpy,bmesh

ob   = bpy.data.objects['Cube']
mesh = bmesh.from_edit_mesh(ob.data)
for v in mesh.verts:
v.select = True

# trigger viewport update
bpy.context.scene.objects.active = bpy.context.scene.objects.active


Docs

• What's the need for the ob variable? – rien333 Feb 2 '18 at 10:30
• I believe it's just so you don't have to keep typing bpy.data.objects['Cube'], for instance, where it's accessed again in bmesh.from_edit_mesh(ob.data) – andyV Jul 21 at 5:44
• thanks for this simple example. arent we suppose to free the bmesh after ? – DB3D Sep 24 at 21:14