python-tabulate icon indicating copy to clipboard operation
python-tabulate copied to clipboard

Fix #124. Improve error reporting when non-iterable data provided.

Open ilya112358 opened this issue 3 years ago • 0 comments

Fix #124. Also related to #208 and #191.

This is to provide an additional message to the user when the program throws a ... is not iterable exception.

Two blocks of try-except added: one for the case when a non-iterable is passed and another when an iterable of non-iterables is passed.

Typical output:

>>> print(tabulate({"a": 1, "b": 2}))
Traceback (most recent call last):
  File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 1373, in _normalize_tabular_data
    izip_longest(*tabular_data.values())
TypeError: 'int' object is not iterable

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 2080, in tabulate
    list_of_lists, headers = _normalize_tabular_data(
                             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\Ibo\Python\python-tabulate\tabulate\__init__.py", line 1376, in _normalize_tabular_data
    raise TypeError(err_msg)
TypeError:

To build a table python-tabulate requires two-dimensional data like a list of lists or similar.
Did you forget a pair of extra [] or ',' in ()?
>>>

ilya112358 avatar Dec 28 '22 14:12 ilya112358