MCPcopy Index your code
hub / github.com/python/cpython / shorten

Function shorten

Lib/textwrap.py:398–411  ·  view source on GitHub ↗

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("Hell

(text, width, **kwargs)

Source from the content-addressed store, hash-verified

396 return w.fill(text)
397
398def shorten(text, width, **kwargs):
399 """Collapse and truncate the given text to fit in the given width.
400
401 The text first has its whitespace collapsed. If it then fits in
402 the *width*, it is returned as is. Otherwise, as many words
403 as possible are joined and then the placeholder is appended::
404
405 >>> textwrap.shorten("Hello world!", width=12)
406 'Hello world!'
407 >>> textwrap.shorten("Hello world!", width=11)
408 'Hello [...]'
409 """
410 w = TextWrapper(width=width, max_lines=1, **kwargs)
411 return w.fill(' '.join(text.strip().split()))
412
413
414# -- Loosely related functionality -------------------------------------

Callers 2

check_shortenMethod · 0.90

Calls 5

fillMethod · 0.95
TextWrapperClass · 0.70
joinMethod · 0.45
splitMethod · 0.45
stripMethod · 0.45

Tested by 2

check_shortenMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…