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?
Asked
Active
Viewed 1,721 times
2

Little Alien
- 1
- 8
- 22
2 Answers
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
-
*Every object has a dictionary* is **False**: `[].__dict__`? Accessing `__dict__` may work in OP's case if they have a function – Moses Koledoye Jul 21 '16 at 16:31
-
`bpy.ops.render.__dict__` fails `with AttributeError __dict__` – Little Alien Jul 21 '16 at 16:34
-
but `getattr` seems to give what I want. – Little Alien Jul 21 '16 at 16:38
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