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

Popular posts from this blog

Command prompt result in label. Python 2.7 -

javascript - How do I use URL parameters to change link href on page? -

amazon web services - AWS Route53 Trying To Get Site To Resolve To www -