AST objects, regardless of the input used to create them, may be converted to parse trees represented as list- or tuple- trees, or may be compiled into executable code objects. Parse trees may be extracted with or without line numbering information.
ast[, line_info]) |
If line_info is true, line number information will be included for all terminal tokens as a third element of the list representing the token. Note that the line number provided specifies the line on which the token ends. This information is omitted if the flag is false or omitted.
ast[, line_info]) |
If line_info is true, line number information will be included for all terminal tokens as a third element of the list representing the token. This information is omitted if the flag is false or omitted.
ast[, filename = '<ast>' ]) |
Compiling an AST object may result in exceptions related to
compilation; an example would be a SyntaxError caused by the
parse tree for del f(0)
: this statement is considered legal
within the formal grammar for Python but is not a legal language
construct. The SyntaxError raised for this condition is
actually generated by the Python byte-compiler normally, which is why
it can be raised at this point by the parser module. Most
causes of compilation failure can be diagnosed programmatically by
inspection of the parse tree.
See About this document... for information on suggesting changes.