On this page
textwrap.shorten
Prev: textwrap.indent | Up: textwrap | Next: textwrap.TextWrapper
Rel: textwrap.dedent, textwrap.fill, textwrap.indent, textwrap.TextWrapper
Ref: docs.python.org — textwrap.shorten
Tags: #public #python3 #stdlib #textwrap
Import
import textwrap
from textwrap import shorten
Signature & Overview
textwrap.shorten(text, width, **kwargs)
Collapse and truncate the given text to fit in the given width.
Usage
import textwrap
assert textwrap.shorten('Hello world from Python', width=16, placeholder='...') == 'Hello world...'
Gotchas
- Collapses all internal whitespace to single spaces and never splits mid-word.
REPL Inspect
from textwrap import shorten
help(shorten)
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/indent 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