generating byte code from compiler.parse output

Chris Wright caw at cs.mu.oz.au
Thu Aug 7 21:05:34 EDT 2003


Is there a way to go from the AST output of compiler.paser to byte
code

i.e. in the example below, is there a way to compile m and get a code
object that could then be called?

cheers and thanks for the help

chris wright

>>> s = """
... def test(x):
... 	y = x + 1
... 	print x, y
... """
>>> m = compiler.parse(s)
>>> m
Module(None, Stmt([Function('test', ['x'], [], 0, None,
Stmt([Assign([AssName('y', 'OP_ASSIGN')], Add((Name('x'), Const(1)))),
Printnl([Name('x'), Name('y')], None)]))]))
>>>




More information about the Python-list mailing list