1.2.1 示例数据
需要美观打印(pretty-pprinting)的情况下,可以使用textwrap模块格式化要输出的文本。它提供了很多文本编辑器和字处理器中都有的段落自动换行或填充特性。
本节中的例子会使用模块textwrap_example.py,其中包含一个字符串sample_text。
# textwrap_example.py
sample_text = '''
The textwrap module can be used to format text for output in situations
where pretty-printing is desired. It offers programmatic functionality
similar to the paragraph wrapping or filling features found un many text
editors.
'''