ast.parse()
ast.parse() is a Python function in the AST Module category. Parses Python source code into an AST (Abstract Syntax Tree). The syntax is ast.parse(source, filename="", mode="exec", *, type_comments=False, feature_version=None). Returns: AST Module node. A typical example: tree = ast.parse("x = 42\nprint(x)")
print(ast.dump(tree, indent=2))
# Module(
# body=[
# Assign(targets=[Name(id='x')], value=Constant(42)),
# ...]). A close sibling is ast.literal_eval(), which safely evaluates a string containing a Python literal (list, dict, tuple, number, string, bool, None). A close sibling is ast.dump(), which returns a formatted string representation of an AST node. A close sibling is ast.walk(), which recursively yields all descendant AST nodes (depth-first). A close sibling is ast.get_source_segment(), which returns the source code segment corresponding to an AST node. More about this category: Abstract Syntax Tree — literal_eval, parse, dump, walk. Related AST Module entries: ast.literal_eval(), ast.dump(), ast.walk(), ast.get_source_segment(), ast.fix_missing_locations(), ast.copy_location().