本文整理汇总了Python中terminaltables.AsciiTable.justify_columns方法的典型用法代码示例。如果您正苦于以下问题:Python AsciiTable.justify_columns方法的具体用法?Python AsciiTable.justify_columns怎么用?Python AsciiTable.justify_columns使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terminaltables.AsciiTable
的用法示例。
在下文中一共展示了AsciiTable.justify_columns方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __report_summary_labels
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns [as 别名]
def __report_summary_labels(self, cumulative):
data = [("label", "status", "succ", "avg_rt", "error")]
justify = {0: "left", 1: "center", 2: "right", 3: "right", 4: "left"}
sorted_labels = sorted(cumulative.keys())
for sample_label in sorted_labels:
if sample_label != "":
data.append(self.__get_sample_element(cumulative[sample_label], sample_label))
table = SingleTable(data) if sys.stdout.isatty() else AsciiTable(data)
table.justify_columns = justify
self.log.info("Request label stats:\n%s", table.table)
示例2: test_multi_line
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns [as 别名]
def test_multi_line():
"""Test multi-lined cells."""
table_data = [
['Show', 'Characters'],
['Rugrats', 'Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles,\nDil Pickles'],
['South Park', 'Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick']
]
table = AsciiTable(table_data)
# Test defaults.
actual = table.table
expected = (
'+------------+-------------------------------------------------------------------------------------+\n'
'| Show | Characters |\n'
'+------------+-------------------------------------------------------------------------------------+\n'
'| Rugrats | Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, |\n'
'| | Dil Pickles |\n'
'| South Park | Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick |\n'
'+------------+-------------------------------------------------------------------------------------+'
)
assert actual == expected
# Test inner row border.
table.inner_row_border = True
actual = table.table
expected = (
'+------------+-------------------------------------------------------------------------------------+\n'
'| Show | Characters |\n'
'+------------+-------------------------------------------------------------------------------------+\n'
'| Rugrats | Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, |\n'
'| | Dil Pickles |\n'
'+------------+-------------------------------------------------------------------------------------+\n'
'| South Park | Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick |\n'
'+------------+-------------------------------------------------------------------------------------+'
)
assert actual == expected
# Justify right.
table.justify_columns = {1: 'right'}
actual = table.table
expected = (
'+------------+-------------------------------------------------------------------------------------+\n'
'| Show | Characters |\n'
'+------------+-------------------------------------------------------------------------------------+\n'
'| Rugrats | Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, |\n'
'| | Dil Pickles |\n'
'+------------+-------------------------------------------------------------------------------------+\n'
'| South Park | Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick |\n'
'+------------+-------------------------------------------------------------------------------------+'
)
assert actual == expected
示例3: display_pull_stats
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns [as 别名]
def display_pull_stats(reviewers, reviewer_workload):
table_data = [
['Assignee', '# assigned'],
]
total = 0
for reviewer in reviewers:
workload = reviewer_workload[reviewer]
table_data.append(
[reviewer, six.text_type(workload)]
)
total += workload
table_data.append(['TOTAL: ', six.text_type(total)])
table = AsciiTable(table_data)
table.inner_footing_row_border = True
table.justify_columns = {1: 'center'}
print(table.table)
示例4: test_multi_line
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import justify_columns [as 别名]
def test_multi_line():
"""Test multi-line tables."""
table_data = [
['Show', 'Characters'],
['Rugrats', dedent('Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles,\n'
'Susie Carmichael, Dil Pickles, Kimi Finster, Spike')],
['South Park', 'Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick']
]
table = AsciiTable(table_data)
expected = dedent("""\
+------------+-------------------------------------------------------------------------------------+
| Show | Characters |
+------------+-------------------------------------------------------------------------------------+
| Rugrats | Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, |
| | Susie Carmichael, Dil Pickles, Kimi Finster, Spike |
| South Park | Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick |
+------------+-------------------------------------------------------------------------------------+""")
assert expected == table.table
table.inner_row_border = True
expected = dedent("""\
+------------+-------------------------------------------------------------------------------------+
| Show | Characters |
+------------+-------------------------------------------------------------------------------------+
| Rugrats | Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, |
| | Susie Carmichael, Dil Pickles, Kimi Finster, Spike |
+------------+-------------------------------------------------------------------------------------+
| South Park | Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick |
+------------+-------------------------------------------------------------------------------------+""")
assert expected == table.table
table.justify_columns = {1: 'right'}
expected = dedent("""\
+------------+-------------------------------------------------------------------------------------+
| Show | Characters |
+------------+-------------------------------------------------------------------------------------+
| Rugrats | Tommy Pickles, Chuckie Finster, Phillip DeVille, Lillian DeVille, Angelica Pickles, |
| | Susie Carmichael, Dil Pickles, Kimi Finster, Spike |
+------------+-------------------------------------------------------------------------------------+
| South Park | Stan Marsh, Kyle Broflovski, Eric Cartman, Kenny McCormick |
+------------+-------------------------------------------------------------------------------------+""")
assert expected == table.table