1
$\begingroup$

is it possible to somehow execute this, so that I get the status of the show_name option?

import bpy

a = "show_name" 
b = "bpy.data.scenes['Scene'].objects['Cube']" + "." + a
$\endgroup$

1 Answer 1

3
$\begingroup$

You can use

eval(b)

eval() will take any valid Python expression string as argument.

To set a value, use

exec(c)

But be careful, exec() will execute ANY python code, so it is considered a very dangerous command, especially if the string is from user input.

I would advice rethinking how your code is setup, there is usually very little reason to access bpy in these fashion.

$\endgroup$
2
  • $\begingroup$ Is it possible to also set a value? For example: a = "show_name" b = "bpy.data.objects['Cube']" + "." + a + " = True" c = eval(b) This doesn’t seem to work unfortunately. $\endgroup$ Commented Dec 16, 2014 at 14:55
  • $\begingroup$ eval() only works with 'expressions'. To set something is a statement. I edited my answer to reflect that. $\endgroup$
    – Mike Pan
    Commented Dec 16, 2014 at 18:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .