import:: import textwrap doc:: textwrap desc:: 文本自动换行与填充 textwrap.fill() 主要是可以指定字符换行 1textwrap.fill(2 str,3 width=42, # 最大框度4 initial_indent=" " # 首行缩进5 subsequent_indent="" # 非首行缩进(前缀)6 ) textwrap.dedent() 去除行前空格 1textwrap.dedent(str) textwrap.indent() 为每一行自动增加缩进或是指定符号,同样也可以使用 fill 中的 subsequent_indent 实现。 1textwrap.indent(str, ">") textwrap.shorten() 长文本截断 1textwrap.shorten(2 str,3 width=10, # 指定长度后截断4 placeholder="..." # 截断占位符,默认值是 [...]5 )6# 返回: 'Hello...' 中文分词可使用jieba