Turning string into executable python code, and holding that variable name -
i'm looping on following:
a might equal task, wash_dishes or play_piano
exec("%a = production(precondition({%s}),action({%s},{%s}))" %(a, precondition, stop, start)) list_a.append(a)
expect: list_a = [wash_dishes, play_piano] (where wash_dishes production created above, not "wash_dishes")
a
holds string (parsed json), , want add value of a
(as variable) list.
thanks in advance! hope made sense!
use dictionary. in exec()
code, put quotes around place variable substituted, use value string.
symboltable = {} exec("symboltable['%s'] = production(precondition({%s}),action({%s},{%s}))" %(a, precondition, stop, start)) list_a.append(symboltable[a])
Comments
Post a Comment