O'Reilly logo

The Python 3 Standard Library by Example, Second Edition by Doug Hellmann

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required