Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d003a2a

Browse files
committed
Describe textwrap module
1 parent ca0383d commit d003a2a

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

Doc/whatsnew/whatsnew23.tex

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
%
2525
% getopt.gnu_getopt
2626
%
27-
% textwrap.py
28-
%
2927
% Docstrings now optional (with --without-doc-strings)
3028
%
3129
% New dependency argument to distutils.Extension
@@ -468,6 +466,41 @@ \section{New and Improved Modules}
468466

469467
\begin{itemize}
470468

469+
\item The \module{textwrap} module contains functions for wrapping
470+
strings containing paragraphs of text. The \function{wrap(\var{text},
471+
\var{width})} function takes a string and returns a list containing
472+
the text split into lines of no more than the chosen width. The
473+
\function{fill(\var{text}, \var{width})} function returns a single
474+
string, reformatted to fit into lines no longer than the chosen width.
475+
(As you can guess, \function{fill()} is built on top of
476+
\function{wrap()}. For example:
477+
478+
\begin{verbatim}
479+
>>> import textwrap
480+
>>> paragraph = "Not a whit, we defy augury: ... more text ..."
481+
>>> textwrap.wrap(paragraph, 60)
482+
["Not a whit, we defy augury: there's a special providence in",
483+
"the fall of a sparrow. If it be now, 'tis not to come; if it",
484+
...]
485+
>>> print textwrap.fill(paragraph, 35)
486+
Not a whit, we defy augury: there's
487+
a special providence in the fall of
488+
a sparrow. If it be now, 'tis not
489+
to come; if it be not to come, it
490+
will be now; if it be not now, yet
491+
it will come: the readiness is all.
492+
>>>
493+
\end{verbatim}
494+
495+
The module also contains a \class{TextWrapper} class that actually
496+
implements the text wrapping strategy. Both the
497+
\class{TextWrapper} class and the \function{wrap()} and
498+
\function{fill()} functions support a number of additional keyword
499+
arguments for fine-tuning the formatting; consult the module's
500+
documentation for details.
501+
% XXX add a link to the module docs?
502+
(Contributed by Greg Ward.)
503+
471504
\item One minor but far-reaching change is that the names of extension
472505
types defined by the modules included with Python now contain the
473506
module and a \samp{.} in front of the type name. For example, in

0 commit comments

Comments
 (0)