Evaluating Dynamically Generated Statements In Python
I need to dynamically generate python code and execute it with eval() function. What I would like to do is to generate some 'imports' and 'assign values'. I mean, I need to generat
Solution 1:
You want exec instead of eval.
>>>s = "x = 2">>>exec s>>>x
2
Of course, please don't use exec on untrusted strings ...
Post a Comment for "Evaluating Dynamically Generated Statements In Python"