Convert "Existing" Mesh to Bmesh (AttributeError: module 'bmesh' has no attribute 'from__mesh') In Blender2.79, the "Main Script" below converts an existing mesh(default_cube) to a "Bmesh" (using bmesh.from_mesh()) and stores the selected vertices of the mesh in a list.  

On testing,this Bmesh example(create new vert on existing selected Mesh) works fine.  

However,when run the MainScript in both Edit and Object(after calculating selected vertices in edit mode) modes ,the console gives this error.  

AttributeError: module 'bmesh' has no attribute 'from__mesh'   


Since,the selected object has to be accessed as a part of the "active" scene, assigning object in this manner ,gives above error    

scene = bpy.context.scene
ob = scene.objects.active
me = ob.data
bm = bmesh.new()
bm = bm.from_mesh(me)


Also direct context assignment gives above error.  

ob = bpy.context.object
me = ob.data
bm = bmesh.new()
bm.from_mesh(me)   


[![Bmesh.from_mesh() error][2]][2]

However, "from_mesh" is a valid attribute in Bmesh module.

Even using bmesh.from_object() gives a similar error.  

AttributeError: module 'bmesh' has no attribute 'from__object'   


Also,if bmesh.from_edit_mesh() is used , and even if the selected object is in Edit mode ,the console gives the following error(even if the Bmesh is set_free after this line)  

ReferenceError: BMesh data of type BMesh has been removed 


How to run this script in EDIT mode using Bmesh module (without getting any errors)? 

----------------------------------MAIN SCRIPT-------------------------------  

from os import system
   system("cls")

import bpy 
import bmesh

#Assign object as a part of the active scene
scene = bpy.context.scene
ob = scene.objects.active
vert = ob.data.vertices

#Set default mode == Edit 
if bpy.ops.object.mode_set.poll():
    bpy.ops.object.mode_set(mode='EDIT')

print("Active object = ",ob.name)

#Store selected vertices in a list
print("vert_selected")
#ob = bpy.context.object #Also direct context assignment raised no attribute error
me = ob.data
bm = bmesh.new()
bm = bm.from_mesh(me) #AttributeError: module 'bmesh' has no attribute 'from_mesh'
#bm.from__object(me) #AttributeError: module 'bmesh' has no attribute 'from__object'

vert_selected = [v.co for v in bm.verts if v.select]   
for vs_s in vert_selected:
    print(vs_s)


bpy.ops.mesh.select_all(action='DESELECT')
bm.select_flush(True)

bpy.ops.object.mode_set(mode='OBJECT') # if bmesh.from_edit_mesh() --&gt; mode == EDIT - ValueError: to_mesh(): Mesh 'Cube' is in editmode 

bm.to_mesh(me) #If mode ==Object  -&gt; ReferenceError: BMesh data of type BMesh has been removed
bm.free() 
ob.update_from_editmode()
A changed the way you selected active object and the way bmesh.from_mesh was called.

from os import system
   system("cls")

import bpy 
import bmesh

#Assign object as a part of the active scene
scene = bpy.context.scene
ob = bpy.context.object
vert = ob.data.vertices

#Set default mode == Edit 
if bpy.ops.object.mode_set.poll():
    bpy.ops.object.mode_set(mode='EDIT')

print("Active object = ",ob.name)

#Store selected vertices in a list
print("vert_selected")
#ob = bpy.context.object #Also direct context assignment raised no attribute error
me = ob.data
bm = bmesh.new()         # Create a new bmesh container instance
bm.from_mesh(me)         # Pass your mesh into this container

vert_selected = [v.co for v in bm.verts if v.select]   
for vs_s in vert_selected:
    print(vs_s)


bpy.ops.mesh.select_all(action='DESELECT')
bm.select_flush(True)

bpy.ops.object.mode_set(mode='OBJECT') # if bmesh.from_edit_mesh() --&gt; mode == EDIT - ValueError: to_mesh(): Mesh 'Cube' is in editmode 

bm.to_mesh(me) #If mode ==Object  -&gt; ReferenceError: BMesh data of type BMesh has been removed
bm.free() 
ob.update_from_editmode()
```