|
24 | 24 | % |
25 | 25 | % getopt.gnu_getopt |
26 | 26 | % |
27 | | -% textwrap.py |
28 | | -% |
29 | 27 | % Docstrings now optional (with --without-doc-strings) |
30 | 28 | % |
31 | 29 | % New dependency argument to distutils.Extension |
@@ -468,6 +466,41 @@ \section{New and Improved Modules} |
468 | 466 |
|
469 | 467 | \begin{itemize} |
470 | 468 |
|
| 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 | + |
471 | 504 | \item One minor but far-reaching change is that the names of extension |
472 | 505 | types defined by the modules included with Python now contain the |
473 | 506 | module and a \samp{.} in front of the type name. For example, in |
|
0 commit comments