On this page
textwrap.indent
Prev: textwrap.fill | Up: textwrap | Next: textwrap.shorten
Rel: textwrap.dedent, textwrap.fill, textwrap.shorten, textwrap.TextWrapper
Ref: docs.python.org — textwrap.indent
Tags: #public #python3 #stdlib #textwrap
Import
import textwrap
from textwrap import indent
Signature & Overview
textwrap.indent(text, prefix, predicate=None)
Adds 'prefix' to the beginning of selected lines in 'text'.
Usage
import textwrap
assert textwrap.indent('a\n\nb\n', '> ') == '> a\n\n> b\n'
Gotchas
- Skips whitespace-only lines by default: Pass
predicate=lambda line: Trueto indent blank lines too.
REPL Inspect
from textwrap import indent
help(indent)
Linked from
Related notes
- tuts/python3/stdlib_module/textwrap/dedent Linked here; links to this page; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap/fill Linked here; links to this page; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap/shorten Linked here; links to this page; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap/TextWrapper Linked here; links to this page; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/textwrap/wrap links to this page; shared tags: #stdlib, #textwrap
- tuts/c/stdlib shared tags: #stdlib
- tuts/c/stdlib/assert shared tags: #stdlib
- tuts/c/stdlib/assert/assert shared tags: #stdlib
- tuts/c/stdlib/assert/static_assert shared tags: #stdlib