get return or locals from "exec" str in "environment"
lucas
sjlukacs at gmail.com
Thu Aug 30 18:11:11 EDT 2012
ok, i am stuck. i tried some test code attempts and i am stuck. so here is some sample code:
xx2 = """
def lucas53():
harry = (4+16)/2
rtn = dict(harry=harry)
return rtn
"""
and then i run:
env = {}
exec xx2 in env
lst = env
and lst returns a huge dictionary of many types, some excerpts are:
{...
...'globals': <built-in function globals>, ...
...'vars': <built-in function vars>, ...
...'locals': <built-in function locals>, ...
...'lucas53': <function lucas53 at 0x214348c>}
and i can see my executed function in there as a type function, and local and global vars, but i can not access or find "harry" or "rtn" the variables within the function lucas53. i do not know how to access the local variables within lucas53 or the locals to find harry or rtn. i really just want the return dictionary. make sense?
anyway, python impresses me with its graceful and concise code, but i really have not found the solution to this mess.
please advise and thank you in advance. lucas
More information about the Python-list
mailing list