Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
79997ed5
Commit
79997ed5
authored
Feb 23, 2014
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
whatsnew: textwrap.shorten.
Also add the missing TextWrapper.shorten method doc.
parent
d3dc4c94
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
0 deletions
+24
-0
Doc/library/textwrap.rst
Doc/library/textwrap.rst
+10
-0
Doc/whatsnew/3.4.rst
Doc/whatsnew/3.4.rst
+14
-0
No files found.
Doc/library/textwrap.rst
View file @
79997ed5
...
...
@@ -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
Doc/whatsnew/3.4.rst
View file @
79997ed5
...
...
@@ -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
---------
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment