Answer the question
In order to leave comments, you need to log in
How to change external objects in the python code of the executable in exec()?
There is this code:
def executeRule(stdout, rule):
obj = None
try:
parsedJson = json.loads(stdout)
pyCmd = 'obj = parsedJson' + rule
exec( pyCmd )
except BaseException as e:
print( e, file=sys.stderr)
return obj
Answer the question
In order to leave comments, you need to log in
In exec and eval, you can directly set global and local variables: eval(expression[, globals[, locals]])
>>> obj = None
>>> exec("obj = 2", {}, locals())
>>> print obj
2
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question