px普贤教程PuXian
普贤教程 › 包参考

textwrap 包

文本排版(换行/缩进/去缩进)

项值
包名textwrap
版本0.2.0
可用版本0.1.0 / 0.2.0
入口textwrap.px
分类文本与中文处理
文件数 / 行数1 / 304

安装与引入

bash
pxpkg init          # 首次
pxpkg add textwrap@0.2.0
pxpkg install
px
import textwrap
所属分类教程:文本与中文处理

公开接口

函数参数
tw_wraps, width
tw_fills, width
tw_dedents
tw_indents, prefix
其余 13 个 def(内部与辅助,可直接调用但不属稳定接口)
函数参数
tw_split_wordss
tw_centers, width, fillchar = " "
tw_ljusts, width, fillchar = " "
tw_rjusts, width, fillchar = " "
tw_strip_liness
tw_shortens, width, placeholder = "..."
tw_split_paragraphss
tw_line_counts
tw_is_cjkc
tw_word_counts
tw_expandtabss, tabsize = 8
tw_rstrip_liness
tw_fill_indents, width, initial_indent = "", subsequent_indent = ""

包内说明(源码头注释)

text
============================================================
普贤生态库:registry/textwrap —— 文本排版(换行/缩进/去缩进)
------------------------------------------------------------
纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。
tw_wrap(s, width)   → [str]   按词断行(默认词间单空格,空行保留)
tw_fill(s, width)   → str     wrap 后用 "\n" 连接
tw_dedent(s)        → str     去除所有行的公共前导空白
tw_indent(s, prefix)→ str     给非空行加前缀
说明:
- width 按 rune 计数(len(s),中文每字算 1;实际显示宽度约 2 为排版子集)
============================================================
内部:按 " " 分词