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

ast.increment_lineno

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


Import

import ast
from ast import increment_lineno

Signature & Overview

ast.increment_lineno(node, n=1)

Increment the line number and end line number of each node in the tree starting at node by n. This is useful to "move code" to a different location in a file.

Usage

import ast

tree = ast.parse("x = 1")
ast.increment_lineno(tree, n=10)
assert tree.body[0].lineno == 11

Gotchas

REPL Inspect

from ast import increment_lineno
help(increment_lineno)

Linked from

Related notes