On this page
textwrap.dedent
Up: textwrap | Next: textwrap.fill
Rel: textwrap.fill, textwrap.indent, textwrap.shorten, textwrap.TextWrapper
Ref: docs.python.org — textwrap.dedent
Tags: #public #python3 #stdlib #textwrap
Import
import textwrap
from textwrap import dedent
Signature & Overview
textwrap.dedent(text)
Remove any common leading whitespace from every line in text.
Usage
import textwrap
block = '''
line 1
line 2
'''
assert textwrap.dedent(block).strip() == 'line 1\n line 2'
Gotchas
- Mixed tabs and spaces are NOT treated as equivalent: Keep triple-quoted strings consistently space-indented.
REPL Inspect
from textwrap import dedent
help(dedent)
Linked from
Related notes
- tuts/python3/stdlib_module/textwrap/fill Linked here; links to this page; shared tags: #stdlib, #textwrap
- tuts/python3/stdlib_module/textwrap/indent 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