本文整理汇总了Python中terminaltables.AsciiTable.table_data[i]方法的典型用法代码示例。如果您正苦于以下问题:Python AsciiTable.table_data[i]方法的具体用法?Python AsciiTable.table_data[i]怎么用?Python AsciiTable.table_data[i]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类terminaltables.AsciiTable
的用法示例。
在下文中一共展示了AsciiTable.table_data[i]方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: table
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import table_data[i] [as 别名]
def table(header, rows):
if not HAVE_TERMTAB:
print_error("Missing dependency, install terminaltables (`pip install terminaltables`)")
return
# TODO: Refactor this function, it is some serious ugly code.
content = [header] + rows
# Make sure everything is string
try:
content = [[a.replace('\t', ' ') for a in list(map(unicode, l))] for l in content]
except:
# Python3 way of doing it:
content = [[a.replace('\t', ' ') for a in list(map(str, l))] for l in content]
t = AsciiTable(content)
if not t.ok:
longest_col = t.column_widths.index(max(t.column_widths))
max_length_col = t.column_max_width(longest_col)
if max_length_col > 0:
for i, content in enumerate(t.table_data):
if len(content[longest_col]) > max_length_col:
temp = ''
for l in content[longest_col].splitlines():
if len(l) > max_length_col:
temp += '\n'.join(textwrap.wrap(l, max_length_col)) + '\n'
else:
temp += l + '\n'
content[longest_col] = temp.strip()
t.table_data[i] = content
return t.table
示例2: table
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import table_data[i] [as 别名]
def table(header, rows):
if not HAVE_TERMTAB:
print_error("Missing dependency, install terminaltables (`pip install terminaltables`)")
return
# TODO: Refactor this function, it is some serious ugly code.
content = []
for l in [header] + rows:
to_append = []
for a in l:
if isinstance(a, bytes):
if sys.version_info < (3, 4):
a = a.decode('utf-8', 'ignore')
else:
a = a.decode('utf-8', 'backslashreplace')
if not isinstance(a, six.text_type):
a = six.text_type(a)
to_append.append(a.replace('\t', ' ').replace('\v', '\\v'))
content.append(to_append)
t = AsciiTable(content)
if not t.ok:
t.inner_row_border = True
longest_col = t.column_widths.index(max(t.column_widths))
max_length_col = t.column_max_width(longest_col)
if max_length_col > 0:
for i, content in enumerate(t.table_data):
if len(content[longest_col]) > max_length_col:
temp = ''
for l in content[longest_col].splitlines():
if len(l) > max_length_col:
temp += '\n'.join(textwrap.wrap(l, max_length_col)) + '\n'
else:
temp += l + '\n'
content[longest_col] = temp.strip()
t.table_data[i] = content
return t.table
示例3: AsciiTable
# 需要导入模块: from terminaltables import AsciiTable [as 别名]
# 或者: from terminaltables.AsciiTable import table_data[i] [as 别名]
t1 = AsciiTable(printarray1, title="Working queues")
t1.column_max_width(1)
if not t1.ok:
longest_col = t1.column_widths.index(max(t1.column_widths))
max_length_col = t1.column_max_width(longest_col)
if max_length_col > 0:
for i, content in enumerate(t1.table_data):
if len(content[longest_col]) > max_length_col:
temp = ''
for l in content[longest_col].splitlines():
if len(l) > max_length_col:
temp += '\n'.join(textwrap.wrap(l, max_length_col)) + '\n'
else:
temp += l + '\n'
content[longest_col] = temp.strip()
t1.table_data[i] = content
t2 = AsciiTable(printarray2, title="Idling queues")
t2.column_max_width(1)
if not t2.ok:
longest_col = t2.column_widths.index(max(t2.column_widths))
max_length_col = t2.column_max_width(longest_col)
if max_length_col > 0:
for i, content in enumerate(t2.table_data):
if len(content[longest_col]) > max_length_col:
temp = ''
for l in content[longest_col].splitlines():
if len(l) > max_length_col:
temp += '\n'.join(textwrap.wrap(l, max_length_col)) + '\n'
else:
temp += l + '\n'