python - Simultaneous eval and exec -


Is there a way to evaluate and execute dragon on a string? I have a file that contains a bunch of expressions which should be calculated, maybe something like that.

  F1 (ifilter (myfilter, x)) f2 (x) * f3 (f4 (x)) + f5 (x))  

And run through the eval expression.

Some expressions may want to save their work after doing an expensive operation

  y = g (x); Unfortunately,  y = g (x)  requires a  exec , but receiving the value is  h + j  of  Eval  How does this work? 

Try using Biltin compile () . When you use it in single mode, it manages both the cases you want. For example:

  compile ('3 + 4', 'dummy & gt;', 'single')  

Compiled Code object will return you can execute it with exec () or eval ():

  & gt; & Gt; & Gt; Exec (compile ('3 + 4', 'dummy & gt;', 'single')) 7> gt; & Gt; & Gt; Exec (compile ('x = 3 + 4', 'dummy & gt;', 'singles')) & gt; & Gt; & Gt; Print X7  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -