知识卡片
段落重排应区分首行后续缩进
需要把长段落整理到指定宽度时,可用textwrap.fill(text, width),用initial_indent控制首行、subsequent_indent控制后续行。终端列数可作为宽度参考,但制表符、长单词及宽字符的显示需按具体规则验证,不能把英文空格文本例直接当所有终端的排版保证。它重排文本,不保留原始换行布局。
这张卡片看不懂?
这张卡片的反馈已满 10 条,暂时无法继续提交。
已有反馈 · 0 / 10 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- · 查看原书依据
textwrap模块来重新格式化文本的输出。例如,假设有如下这段长字符串: s = "Look into my eyes, look into my eyes, the eyes, the eyes, \ the eyes, not around the eyes, d
参考来源
- 位置:《Python Cookbook(第3版)中文版》2.16 以固定的列数重新格式化文本(spine10;extracted/Python Cookbook(第3版)中文版/_epub-src/OEBPS/Text/part0008.xhtml;u039-ch02-027)。
- 结论依据:完整读取本条问题、全部代码与讨论;保留格式、缓冲和环境边界,不把历史实现口吻当作当前无条件保证。
- 原始内容:textwrap模块来重新格式化文本的输出。例如,假设有如下这段长字符串: s = "Look into my eyes, look into my eyes, the eyes, the eyes, \ the eyes, not around the eyes, d