2

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?

Little Alien
  • 1
  • 8
  • 22

2 Answers2

3

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')
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
0

If you want to know what is inside a non-subscriptable object that does not have a dict you can do this:

import csv # use csv dialect as example object
a = csv.get_dialect('excel')
field_names = [v for v in dir(a) if not v.startswith('__')]
fields = [(getattr(a, v),v) for v in field_names]

print(fields)
botenvouwer
  • 4,334
  • 9
  • 46
  • 75