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

ast.iter_child_nodes

Prev: ast.increment_lineno | Up: ast | Next: ast.iter_fields
Rel: ast.Add, ast.alias, ast.And, ast.AnnAssign
Ref: docs.python.org — ast.iter_child_nodes
Tags: #public #python3 #stdlib #ast


Import

import ast
from ast import iter_child_nodes

Signature & Overview

ast.iter_child_nodes(node)

Yield all direct child nodes of node, that is, all fields that are nodes and all items of fields that are lists of nodes.

Usage

import ast

tree = ast.parse("x = 1 + 2")
children = list(ast.iter_child_nodes(tree.body[0]))
assert len(children) == 2   # Name('x') and BinOp(1 + 2)

Gotchas

REPL Inspect

from ast import iter_child_nodes
help(iter_child_nodes)

Linked from

Related notes