PyDocs

Nav

Text Processing Services

shorten

textwrap

function · Added in 3.4 (source)
  • shorten(text, width, *, fix_sentence_endings=False, break_long_words=True, break_on_hyphens=True, placeholder=' [...]')
Collapse and truncate the given text to fit in the given width.

The text first has its whitespace collapsed.  If it then fits in
the *width*, it is returned as is.  Otherwise, as many words
as possible are joined and then the placeholder is appended::

    >>> textwrap.shorten("Hello  world!", width=12)
    'Hello world!'
    >>> textwrap.shorten("Hello  world!", width=11)
    'Hello [...]'
1 Example
>>> textwrap.shorten("Hello  world!", width=12)
'Hello world!'
>>> textwrap.shorten("Hello  world!", width=11)
'Hello [...]'
>>> textwrap.shorten("Hello world", width=10, placeholder="...")
'Hello...'
from the Python docs
See Also
No see-alsos for textwrap/shorten
0 Notes
No notes for shorten