[2.54] bpy.ops.object.editmode_toggle() returns AttributeError

When I try and toggle editmode from the console, it works. When I try and run it as a script I get:
AttributeError: ‘NoneType’ object has no attribute ‘ops’

This worked fine in 2.53, but now I’m completely stumped.


import bpy
class OBJECT_OT_testfunc(bpy.types.Operator):
    
    bl_idname="test"
    bl_label="test function"
    @classmethod
    def poll(self, context):
        return (context.active_object != None)

    def execute(self, context):
        #making sure to be in object mode...
        if context.mode != 'OBJECT':
            bpy.ops.object.editmode_toggle()


        #CODE OMITTED FOR TESTING


        bpy.ops.object.editmode_toggle()
        return {'FINISHED'}

class OBJECT_PT_testpanel(bpy.types.Panel):
    bl_label = "Test Panel"
    bl_space_type = "PROPERTIES"
    bl_region_type = "WINDOW"
    bl_context = "object"
    def draw(self, context):
        layout = self.layout
        row = layout.row()
        row.operator("test")

Works fine here.

What version of python is blender linked with?

or do a

bpy.ops.object.mode_set(mode='OBJECT')

and be a bit clearer

SVN 32050 your script works …

Just tried it in 32175… and I still get the same error:

AttributeError: ‘NoneType’ object has no attribute ‘ops’

Python 3.1.1 --according to the console.

Apparently Python 3.1.1 has a bug that doesn’t let you so stuff like ‘import bpy’ which is why it claims NoneType (aka bpy) object has no attribute ‘ops’.

Either have to build blender yourself using 3.1.2 or wait until the (OSX I’m guessing) lib builder gets around to updating them in trunk.