Python对每一行和每一段进行文本扭曲



我需要对每一行超过80个字符的文字进行换行,并将长段落分解为80个字符块。每行和每段的末尾都有一个。

This is the first line of text with more than eighty characters in this sentence.**n**  
**n**  
This line of text is less than eighty characters.**n**  
**n**  
This is the first sentence of the first paragraph. This is the second sentence of the first paragraph. This is the third sentence of the first paragraph. This is the fourth sentence of the first paragraph. This is the fifth sentence of the first paragraph.**n**  
**n**  
This is the first sentence of the second paragraph. This is the second sentence of the second paragraph. This is the third sentence of the second paragraph. This is the fourth sentence of the second paragraph.**n**    

我需要这样的输出:

This is the very first line of text with more than eighty characters in this **n**  
sentence.**n**  
**n**  
This line of text is less than eighty characters.**n**  
**n**  
This is the first sentence of the first paragraph. This is the second sentence **n**  
of the first paragraph. This is the third sentence of the first paragraph. This **n**  
is the fourth sentence of the first paragraph. This is the fifth sentence of the **n**  
first paragraph.**n**  
**n**  
This is the first sentence of the second paragraph. This is the second sentence **n**  
of the second paragraph. This is the third sentence of the second paragraph. This **n**  
is the fourth sentence of the second paragraph.**n**  
>>> import textwrap
>>> help(textwrap)

最新更新