pythonpython-3.xreferenceattributesmembers

Accessing non-subscriptable properties


Scripting the Blender, I successfully did bpy.ops.render.render(some_args) but bpy.ops.render['render'] fails with BPyOpsSubMod object is not subscriptable. This puzzles me since I expected that, likewise in Javascript, any Python object is a dictionary and I can access object methods either by obj.member or obj['member']. How do I work around the non-subscriptable properties when I want to reference them by name?


Solution

  • It's not true that every object is a dictionary. But most objects have a dictionary, accessible through the name .__dict__.

    You can use either

    bpy.ops.render.__dict__['render']
    

    or

    getattr(bpy.ops.render, 'render')