On this page
  1. ast.dump
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

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

REPL Inspect

from ast import dump
help(dump)

Linked from

Related notes