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

ast.iter_fields

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


Import

import ast
from ast import iter_fields

Signature & Overview

ast.iter_fields(node)

Yield a tuple of (fieldname, value) for each field in node._fields that is present on node.

Usage

import ast

node = ast.parse("1 + 2", mode="eval").body
fields = dict(ast.iter_fields(node))
assert set(fields) == {"left", "op", "right"}

Gotchas

REPL Inspect

from ast import iter_fields
help(iter_fields)

Linked from

Related notes