【发布时间】:2013-08-16 11:02:39
【问题描述】:
propertiesTextBlock = """
Basic Properties
----------------
- nodes (n) {n}
- edges (m) {m}
- min. degree {minDeg}
- max. degree {maxDeg}
- isolated nodes {isolates}
- self-loops {loops}
- density {dens:10.6f}
"""
使用string.format 插入了几个数据项。输出到控制台然后看起来像:
Basic Properties
----------------
- nodes (n) 10680
- edges (m) 24316
- min. degree 1
- max. degree 205
- isolated nodes 0
- self-loops 0
- density 0.000426
并不完美,因为我需要在文本块中手动插入正确数量的标签。另外,如果我想以不同的方式对齐数字怎么办(例如右对齐所有内容,对齐. ...)
有没有一种简单的方法可以确保这张桌子看起来不错?
【问题讨论】:
-
您可以使用prettytable 格式代替此表格形式吗?
-
@alecxe 理想情况下,我希望输出为降价格式。 Prettytable 与它兼容吗?
-
你知道格式语法支持文本左右对齐吗?
-
@cls nope,prettytable 只是用于可视化表格
-
@cls 也看看tabulate 模块,可能会有所帮助。
标签: python string python-3.x format