diff options
| author | R David Murray <rdmurray@bitdance.com> | 2014-02-23 15:22:07 (GMT) |
|---|---|---|
| committer | R David Murray <rdmurray@bitdance.com> | 2014-02-23 15:22:07 (GMT) |
| commit | 6e1bc7cab916ade2ec8c696f20d8ca3a8bb5b235 (patch) | |
| tree | ba46f2d0d4094c59427c6df28dffa5e7a332e755 | |
| parent | a183064d8600b0fdcd43e24973f1b8dff80977c0 (diff) | |
| download | cpython-6e1bc7cab916ade2ec8c696f20d8ca3a8bb5b235.zip cpython-6e1bc7cab916ade2ec8c696f20d8ca3a8bb5b235.tar.gz cpython-6e1bc7cab916ade2ec8c696f20d8ca3a8bb5b235.tar.bz2 | |
whatsnew: textwrap.shorten.
Also add the missing TextWrapper.shorten method doc.
| -rw-r--r-- | Doc/library/textwrap.rst | 10 | ||||
| -rw-r--r-- | Doc/whatsnew/3.4.rst | 14 |
2 files changed, 24 insertions, 0 deletions
diff --git a/Doc/library/textwrap.rst b/Doc/library/textwrap.rst index 1ba42a3..0188729 100644 --- a/Doc/library/textwrap.rst +++ b/Doc/library/textwrap.rst @@ -282,3 +282,13 @@ hyphenated words; only then will long words be broken if necessary, unless Wraps the single paragraph in *text*, and returns a single string containing the wrapped paragraph. + + + .. method:: shorten(text, width=70, *, 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 unchanged. Otherwise, as many words + as possible are joined and then the *placeholder* is appended. + + .. versionadded:: 3.4 diff --git a/Doc/whatsnew/3.4.rst b/Doc/whatsnew/3.4.rst index 461a8b8..edc5704 100644 --- a/Doc/whatsnew/3.4.rst +++ b/Doc/whatsnew/3.4.rst @@ -1210,6 +1210,20 @@ especially if automated via a test suite. (Contributed by Antoine Pitrou in :issue:`13390`.) +textwrap +-------- + +:mod:`textwrap` has a new function :func:`~textwrap.shorten`, implemented via a +new :class:`~textwrap.TextWrapper` method +:meth:`~textwrap.TextWrapper.shorten`, that provides a convenient way to create +a string that displays just the leading porting of an input string. It +collapses any whitespace, truncates the result to a specified width, and a +specified placeholder is added (by default, ``[...]``, stored in the new +:attr:`~textwrap.TextWrapper.placeholder` attribute of the +:class:`~textwrap.TextWrapper` object)). (Contributed by Antoine Pitrou in +:issue:`18585`.) + + traceback --------- |
