How to use the beautifultable.helpers.BTRowData 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
type(padding_right).__name__
                )
            )
        if not isinstance(alignment, enums.Alignment):
            raise TypeError(
                "alignment should be of type '{}' not '{}'".format(
                    enums.Alignment.__name__, type(alignment).__name__
                )
            )

        if self._table._ncol == 0:
            self.header = [header]
            self.padding_left = [padding_left]
            self.padding_right = [padding_right]
            self.alignment = [alignment]
            self._table._data = [BTRowData(self._table, [i]) for i in column]
        else:
            if (not isinstance(header, basestring)) and (header is not None):
                raise TypeError(
                    "header must be of type 'str' not '{}'".format(
                        type(header).__name__
                    )
                )
            column_length = 0
            for row, new_item in zip(self._table.rows, column):
                row._insert(index, new_item)
                column_length += 1
            if column_length == len(self._table.rows):
                self._table._ncol += 1
                self.header._insert(index, header)
                self.width._insert(index, 0)
                self.alignment._insert(index, alignment)
github pri22296 / beautifultable / beautifultable / helpers.py View on Github external
def _reset_state(self, nrow):
        self._table._data = type(self._table._data)(
            self._table,
            [
                BTRowData(self._table, [None] * self._table._ncol)
                for i in range(nrow)
            ],
        )
        self.header = BTRowHeader(self._table, [None] * nrow)
github pri22296 / beautifultable / beautifultable / helpers.py View on Github external
------
        TypeError
            If key is not of type int, slice or str.
        IndexError
            If `int` key is out of range.
        KeyError
            If `str` key is not in header.
        """
        if isinstance(key, (int, basestring)):
            self._table._data[key] = BTRowData(self._table, value)
        elif isinstance(key, slice):
            value = [list(row) for row in value]
            if len(self._table.columns) == 0:
                self._table.columns._initialize(len(value[0]))
            self._table._data[key] = [
                BTRowData(self._table, row) for row in value
            ]
        else:
            raise TypeError("key must be int, str or a slice object")
github pri22296 / beautifultable / beautifultable / helpers.py View on Github external
Heading of the row

        Raises
        ------
        TypeError:
            If `row` is not an iterable.

        ValueError:
            If size of `row` is inconsistent with the current number
            of columns.
        """
        if self._table._ncol == 0:
            row = list(row)
            self._table.columns._reset_state(len(row))
        self.header._insert(index, header)
        self._table._data._insert(index, BTRowData(self._table, row))
github pri22296 / beautifultable / beautifultable / helpers.py View on Github external
self._header = BTColumnHeader(self._table, [None] * ncol)
        self._auto_width = True
        self._alignment = AlignmentMetaData(
            self._table, [self.default_alignment] * ncol
        )
        self._width = NonNegativeIntegerMetaData(self._table, [0] * ncol)
        self._padding_left = NonNegativeIntegerMetaData(
            self._table, [self.default_padding] * ncol
        )
        self._padding_right = NonNegativeIntegerMetaData(
            self._table, [self.default_padding] * ncol
        )
        self._table._data = type(self._table._data)(
            self._table,
            [
                BTRowData(self._table, [None] * ncol)
                for i in range(len(self._table._data))
            ],
github pri22296 / beautifultable / beautifultable / helpers.py View on Github external
key : int, slice, str
            If key is an `int`, updates a row.
            If key is an `str`, updates the first row with heading `key`.
            If key is a slice object, updates multiple rows.

        Raises
        ------
        TypeError
            If key is not of type int, slice or str.
        IndexError
            If `int` key is out of range.
        KeyError
            If `str` key is not in header.
        """
        if isinstance(key, (int, basestring)):
            self._table._data[key] = BTRowData(self._table, value)
        elif isinstance(key, slice):
            value = [list(row) for row in value]
            if len(self._table.columns) == 0:
                self._table.columns._initialize(len(value[0]))
            self._table._data[key] = [
                BTRowData(self._table, row) for row in value
            ]
        else:
            raise TypeError("key must be int, str or a slice object")