Chapter 1. Text

The str class is the most obvious text processing tool available to Python programmers, but there are plenty of other tools in the standard library to make advanced text manipulation simple.

Programs may use string.Template as a simple way to parameterize strings beyond the features of str objects. While not as feature-rich as templates defined by many of the web frameworks or extension modules available from the Python Package Index, string.Template is a good middle ground for user-modifiable templates in which dynamic values need to be inserted into otherwise static text.

The textwrap (page 7) module includes tools for formatting text from paragraphs by limiting the width of output, adding indentation, and inserting line breaks ...

Get The Python 3 Standard Library by Example, Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.