Duncan Booth wrote:
> > I would like to compile an AST to bytecode, so I can eval it later.
> I'm not sure there are any properly documented functions for converting an
> AST to a code object, so your best bet may be to examine what a
> pycodegen class like Expression or Module actually does.

Thanks, Duncan. It worked perfectly. :-)

For arbitrary nodes I just had to wrap them inside an Expression node:

>>> ast = compiler.ast.Expression(node)
>>> ast.filename = 'dummy'
>>> c = compiler.pycodegen.ExpressionCodeGenerator(ast)
>>> obj = eval(c.getCode(), scope)

--Rob

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to