"beza1e1" wrote:
> Thank you! this "compile/exec in context" is the thing i wanted.
>
> It is not that performant i think.
it's about as fast as it can get, as long as you only call compile when
the expressions change. (the example didn't show it, but the "expr"
code object can of course be reu
Thank you! this "compile/exec in context" is the thing i wanted.
It is not that performant i think. But it should ease the prototyping.
--
http://mail.python.org/mailman/listinfo/python-list
beza1e1 wrote:
> Is it possible compiler.parse a statement, then change and then
> execute/resolve it?
This should work:
>>> from compiler.pycodegen import ModuleCodeGenerator
>>> from compiler.misc import set_filename
>>> from compiler import parse
>>>
>>> tree = parse('foo = 42')
>>> set
"beza1e1" <[EMAIL PROTECTED]> wrote:
> I have such a statement as string: "distance = x**2 + y**2"
> x and y are undefined, so it is no executable Python code, but it is
> parseable. Now i'd like traverse through the AST and change Name('x')
> for the value i have elsewhere. And finally let Python
Is it possible compiler.parse a statement, then change and then
execute/resolve it?
Background:
I'm probably to lazy to write my own parser.
I have such a statement as string: "distance = x**2 + y**2"
x and y are undefined, so it is no executable Python code, but it is
parseable. Now i'd like tra