这可以通过使用PTable库来实现,该库最初是从PrettyTable分支而来。我在文档中没有找到这个信息,所以对其他人有用的语法如下:
from prettytable import PrettyTable
table = PrettyTable()
table.title = 'Results for method Foo'
table.field_names = ['Experiment', 'Value']
table.add_row(['bla', 3.14])
table.add_row(['baz', 42.0])
print(table)
+-------------------------+
| Results for method Foo |
+---------------+---------+
| Experiment | Value |
+---------------+---------+
| bla | 3.14 |
| baz | 42.0 |
+---------------+---------+