0

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

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**  
4

1 回答 1

5
>>> import textwrap
>>> help(textwrap)
于 2012-08-02T06:32:13.933 回答