I do not understand what environment a eval or exec statement executes in. You can pass both global and local scopes to them but I don't quite understand what this means. Does python create an anonymous module for them, and if that is the case how do the global and local scope differ?
Does it run it like it was an anonymous function? If that was the case the global and local scopes would make more sense to me, although would you still need to call global var
to prevent python from making a local variable on assignment?
And here is some code to show what I am actually trying to do.
# module level vars
result = ''
allowed_builtins = {"__builtins__":{'int':int, 'str':str, 'range':range, 'dir':dir,
'zip':zip
},
"result":result}
In class
def _exec(self, answer, function_name, input):
global result
exec_string = answer + '\n'
exec_string += 'global result; result = %s(%s)' % (function_name, input)
exec exec_string in allowed_builtins, {}
return result
i would like the var result in my scope to be able to be set from within the eval/exec's scope.
QUESTION ASKED!!!!!!!!!