On this page
ast.dump
Prev: ast.copy_location | Up: ast | Next: ast.fix_missing_locations
Rel: ast.Add, ast.alias, ast.And, ast.AnnAssign
Ref: docs.python.org — ast.dump
Tags: #public #python3 #stdlib #ast
Import
import ast
from ast import dump
Signature & Overview
ast.dump(node, annotate_fields=True, include_attributes=False, *, indent=None, show_empty=False)
Return a formatted dump of the tree in node. This is mainly useful for debugging purposes. If annotate_fields is true (by default), the returned string will show the names and the values for fields.
Usage
import ast
text = ast.dump(ast.parse("x = 1"), indent=2)
assert "Assign(" in text and "Constant(value=1)" in text
Gotchas
- Pass
indent=2for readable debugging andinclude_attributes=Truewhen you wantlineno/col_offsetshown.
REPL Inspect
from ast import dump
help(dump)
Linked from
Related notes
- tuts/python3/stdlib_module/ast/copy_location Linked here; links to this page; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/fix_missing_locations Linked here; links to this page; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/Add Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/alias Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/And Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/AnnAssign Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/AST Linked here; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/ast/arg shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/arguments shared tags: #ast, #stdlib