第一章:文本-textwrap:格式化文本段落-示例数据

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

猜你喜欢

转载自blog.csdn.net/weixin_43193719/article/details/86654335