On this page
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
- Yields
(field_name, value)for every present field onnode.
REPL Inspect
from ast import iter_fields
help(iter_fields)
Linked from
Related notes
- tuts/python3/stdlib_module/ast/iter_child_nodes Linked here; links to this page; shared tags: #ast, #stdlib
- tuts/python3/stdlib_module/ast/literal_eval 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