普贤教程 › 包参考
table 包
ASCII/UTF-8 对齐表格渲染
| 项 | 值 |
|---|---|
| 包名 | table |
| 版本 | 0.2.0 |
| 可用版本 | 0.1.0 / 0.2.0 |
| 入口 | table.px |
| 分类 | 文本与中文处理 |
| 文件数 / 行数 | 1 / 279 |
安装与引入
bash
pxpkg init # 首次 pxpkg add table@0.2.0 pxpkg install
px
import table所属分类教程:文本与中文处理
公开接口
| 函数 | 参数 |
|---|---|
tb_render | headers, rows, opts |
其余 10 个 def(内部与辅助,可直接调用但不属稳定接口)
| 函数 | 参数 |
|---|---|
tb_cell_str | v |
tb_widths | headers, rows, pad |
tb_pad_cell | s, width, align |
tb_render_row | row, w, align, pad |
tb_is_wide | c |
tb_display_width | s |
tb_widths_v2 | headers, rows, pad |
tb_pad_cell_v2 | s, width, align |
tb_render_row_v2 | row, w, align, pad |
tb_render_v2 | headers, rows, opts |
包内说明(源码头注释)
text
============================================================ 普贤生态库:registry/table —— ASCII/UTF-8 对齐表格渲染 ------------------------------------------------------------ 纯函数库(无 IO、无状态),编译(px build)与解释(px run)双模式一致。 tb_render(headers, rows, opts) → str 参数: headers : [str] 表头 rows : [[str|数值...]] 数据行(单元格自动 str()) opts : dict 可选: border : "utf8"(默认)| "ascii" align : "left"(默认)| "right" | "center" padding : int(默认 1,单元格两侧空格数) 说明:列宽按 rune 宽度计(len,中文每字 1;与 textwrap 同口径的排版子集, 精确 CJK 双宽留给 0.2.0)。 ============================================================ 内部:单元格转字符串