Message266321
What you're looking for is in the 2nd paragraph of the ast docs:
An abstract syntax tree can be generated by passing
ast.PyCF_ONLY_AST as a flag to the compile() built-in
function, or using the parse() helper provided in this
module. The result will be a tree of objects whose
classes all inherit from ast.AST. An abstract syntax
tree can be compiled into a Python code object using
the built-in compile() function.
For example:
>>> mod = compile('42', '', 'exec', ast.PyCF_ONLY_AST)
>>> mod
<_ast.Module object at 0x7f0e45b15be0
>>> ast.dump(mod)
'Module(body=[Expr(value=Num(n=42))])'
In the discussion of `flags`, I think the compile docs should explicitly list ast.PyCF_ONLY_AST and the CO_FUTURE_* flags in a table. |
|
Date |
User |
Action |
Args |
2016-05-25 08:13:01 | eryksun | set | recipients:
+ eryksun, docs@python, leewz |
2016-05-25 08:13:01 | eryksun | set | messageid: <1464163981.13.0.194675480737.issue27119@psf.upfronthosting.co.za> |
2016-05-25 08:13:01 | eryksun | link | issue27119 messages |
2016-05-25 08:13:00 | eryksun | create | |
|