On this page
inspect.cleandoc
Prev: inspect.classify_class_attrs | Up: inspect | Next: inspect.ClosureVars
Rel: inspect.ArgInfo, inspect.Arguments, inspect.Attribute, inspect.BlockFinder
Ref: docs.python.org — inspect.cleandoc
Tags: #public #python3 #stdlib #inspect
Import
import inspect
from inspect import cleandoc
Signature & Overview
inspect.cleandoc(doc)
Clean up indentation from docstrings.
Usage
import inspect
raw = """Summary line.
Indented body line.
"""
assert inspect.cleandoc(raw) == "Summary line.\n\nIndented body line."
Gotchas
- Standard PEP 257 docstring dedenter: Handles the quirk where line 1 has no indentation while lines 2+ are indented (unlike
textwrap.dedent()).
REPL Inspect
from inspect import cleandoc
help(cleandoc)
Linked from
Related notes
- tuts/python3/stdlib_module/inspect/classify_class_attrs Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClosureVars Linked here; links to this page; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/inspect/ArgInfo Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Arguments Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/Attribute Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BlockFinder Linked here; shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BoundArguments shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/BufferFlags shared tags: #inspect, #stdlib
- tuts/python3/stdlib_module/inspect/ClassFoundException shared tags: #inspect, #stdlib