How to use the beautifultable.compat.zip_longest function in beautifultable

To help you get started, we’ve selected a few beautifultable examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pri22296 / beautifultable / beautifultable / helpers.py View on Github external
table.detect_numerics,
                        table.precision,
                        sign.value,
                    ).split("\n")
                )
                item.maxwidth = curr_maxwidth
            else:
                rows.append(
                    pre_process(
                        item,
                        table.detect_numerics,
                        table.precision,
                        sign.value,
                    ).split("\n")
                )
        for row in map(list, zip_longest(*rows, fillvalue="")):
            for i in range(len(row)):
                row[i] = pre_process(
                    row[i], table.detect_numerics, table.precision, sign.value,
                )
            for row_ in self._clamp_row(row):
                for i in range(len(table.columns)):
                    # str.format method doesn't work for multibyte strings
                    # hence, we need to manually align the texts instead
                    # of using the align property of the str.format method
                    pad_len = width[i] - termwidth(row_[i])
                    if align[i].value == "<":
                        right_pad = " " * pad_len
                        row_[i] = to_unicode(row_[i]) + right_pad
                    elif align[i].value == ">":
                        left_pad = " " * pad_len
                        row_[i] = left_pad + to_unicode(row_[i])
github pri22296 / beautifultable / beautifultable / rows.py View on Github external
width = table.column_widths
        align = table.column_alignments
        sign = table.sign_mode
        lpw = table.left_padding_widths
        rpw = table.right_padding_widths
        string = []
        for i, item in enumerate(self._row):
            if isinstance(item, type(table)):
                # temporarily change the max width of the table
                curr_max_width = item.max_table_width
                item.max_table_width = width[i] - lpw[i] - rpw[i]
                rows.append(to_unicode(item).split("\n"))
                item.max_table_width = curr_max_width
            else:
                rows.append(to_unicode(item).split("\n"))
        for row in map(list, zip_longest(*rows, fillvalue="")):
            for i in range(len(row)):
                row[i] = get_output_str(
                    row[i],
                    table.detect_numerics,
                    table.numeric_precision,
                    sign.value,
                )
            list_of_rows = self._get_row_within_width(row)
            for row_ in list_of_rows:
                for i in range(table.column_count):
                    # str.format method doesn't work for multibyte strings
                    # hence, we need to manually align the texts instead
                    # of using the align property of the str.format method
                    pad_len = width[i] - termwidth(row_[i])
                    if align[i].value == "<":
                        right_pad = " " * pad_len
github pri22296 / beautifultable / beautifultable / helpers.py View on Github external
left_pad
                    + self._clamp_string(row_item, index, delimiter)
                    + right_pad
                )
                row_item_list.append(clmp_str)
            result.append(row_item_list)
        elif wep is enums.WidthExceedPolicy.WEP_WRAP:

            # Let's wrap the row
            string_partition = []

            for index, row_item in enumerate(row):
                width = table.columns.width[index] - lpw[index] - rpw[index]
                string_partition.append(textwrap(row_item, width))

            for row_items in zip_longest(*string_partition, fillvalue=""):
                row_item_list = []
                for index, row_item in enumerate(row_items):
                    left_pad = table.columns._pad_character * lpw[index]
                    right_pad = table.columns._pad_character * rpw[index]
                    row_item_list.append(left_pad + row_item + right_pad)
                result.append(row_item_list)

        return [[""] * len(table.columns)] if len(result) == 0 else result
github pri22296 / beautifultable / beautifultable / rows.py View on Github external
left_pad
                    + self._clamp_string(row_item, index, delimiter)
                    + right_pad
                )
                row_item_list.append(clmp_str)
            list_of_rows.append(row_item_list)
        elif wep is WidthExceedPolicy.WEP_WRAP:

            # Let's wrap the row
            string_partition = []

            for index, row_item in enumerate(row):
                width = table.column_widths[index] - lpw[index] - rpw[index]
                string_partition.append(textwrap(row_item, width))

            for row_items in zip_longest(*string_partition, fillvalue=""):
                row_item_list = []
                for index, row_item in enumerate(row_items):
                    left_pad = table._column_pad * lpw[index]
                    right_pad = table._column_pad * rpw[index]
                    row_item_list.append(left_pad + row_item + right_pad)
                list_of_rows.append(row_item_list)

        if len(list_of_rows) == 0:
            return [[""] * table.column_count]
        else:
            return list_of_rows