Eryk Sun added the comment:

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.

----------
nosy: +eryksun

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue27119>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to