Chapter 1. Text
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.
textwrap (page 7) module includes tools for formatting text from paragraphs by limiting the width of output, adding indentation, and inserting line breaks ...