本文正在参加「Python主题月」,详情查看 活动连接python
用于将 2D Python 列表转换为花哨的 ASCII 表的模块。Table2Ascii 可以让您在终端和 Discord 上显示漂亮的表格。git
pip install table2ascii
复制代码
from table2ascii import table2ascii
output = table2ascii(
header=["#", "G", "H", "R", "S"],
body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
footer=["SUM", "130", "140", "135", "130"],
)
print(output)
复制代码
输出:github
from table2ascii import table2ascii
output = table2ascii(
body=[["Assignment", "30", "40", "35", "30"], ["Bonus", "10", "20", "5", "10"]],
first_col_heading=True,
)
print(output)
复制代码
输出:面试
from table2ascii import table2ascii, Alignment
output = table2ascii(
header=["#", "G", "H", "R", "S"],
body=[["1", "30", "40", "35", "30"], ["2", "30", "40", "35", "30"]],
first_col_heading=True,
column_widths=[5] * 5, # [5, 5, 5, 5, 5]
alignments=[Alignment.LEFT] + [Alignment.RIGHT] * 4, # First is left, remaining 4 are right
)
print(output)
复制代码
输出:编程
from table2ascii import table2ascii, PresetStyle
output = table2ascii(
header=["First", "Second", "Third", "Fourth"],
body=[["10", "30", "40", "35"], ["20", "10", "20", "5"]],
column_widths=[10] * 4,
style=PresetStyle.ascii_box
)
print(output)
复制代码
输出:小程序
查看TableStyle
更多信息和PresetStyle
示例。markdown
from table2ascii import table2ascii, TableStyle
my_style = TableStyle.from_string("*-..*||:+-+:+ *''*")
output = table2ascii(
header=["First", "Second", "Third"],
body=[["10", "30", "40"], ["20", "10", "20"], ["30", "20", "30"]],
style=my_style
)
print(output)
复制代码
输出:多线程
在此处查看全部预设样式的列表。app
全部参数都是可选的。svn
选项 | 类型 | 默认 | 描述 |
---|---|---|---|
header |
List[str] |
None |
表的第一行由标题行分隔符分隔 |
body |
List[List[str]] |
None |
表格主要部分的行列表 |
footer |
List[str] |
None |
表的最后一行由标题行分隔符分隔 |
column_widths |
List[int] |
自动的 | 每列以字符为单位的列宽列表 |
alignments |
List[int] |
所有居中 | 每列的对齐方式 (例如[Alignment.LEFT, Alignment.CENTER, Alignment.RIGHT] ) |
first_col_heading |
bool |
False |
是否在第一列后添加标题列分隔符 |
last_col_heading |
bool |
False |
是否在最后一列前添加标题列分隔符 |
运行测试(pytest)
python setup.py test
去绒(flake8):
python setup.py lint
以上就是本篇文章的所有内容,用于将 2D Python 列表转换为花哨的 ASCII/Unicode 表的模块。我但愿本篇博客可以帮助到你们,博主也在学习进行中,若有什么错误的地方还望批评指正。若是你喜欢这篇文章并但愿看到更多此类文章,能够看看这里(Github/Gitee) 这里汇总了个人所有原创及做品源码,关注我以查看更多文章。
若是你真的从这篇文章中学到了一些新东西,喜欢它,收藏它并与你的小伙伴分享。🤗最后,不要忘了❤或📑支持一下哦