当前位置: 首页>>代码示例>>Python>>正文


Python AsciiTable.table_data[i]方法代码示例

本文整理汇总了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
开发者ID:chubbymaggie,项目名称:viper,代码行数:33,代码来源:out.py

示例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
开发者ID:kevthehermit,项目名称:viper,代码行数:40,代码来源:out.py

示例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'
开发者ID:CIRCL,项目名称:AIL-framework,代码行数:33,代码来源:ModuleInformation.py


注:本文中的terminaltables.AsciiTable.table_data[i]方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。