You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I found a bug when the Table class of table.py when you try to add a row with less columns than the number of headings:
$ cat ~/python/tabletest
#! /usr/bin/env python3
import logging
import argparse
from table import Table
parser = argparse.ArgumentParser(description='investigate table bug')
parser.add_argument('--boom', action='store_true', help='Cause exception')
parser.add_argument('-v', '--verbose', action='count', help='Enable debugging')
args = parser.parse_args()
logging.basicConfig(format='%(asctime)s %(levelname)s %(pathname)s:%(lineno)d %(msg)s')
log = logging.getLogger()
# log.setLevel(logging.DEBUG if args.verbose else logging.WARNING)
log.setLevel(logging.WARNING - (args.verbose or 0)*10)
table = Table('col1', 'col2')
table.add('row1, col1', 'row1, col2')
if args.boom:
table.add('row2, col1')
print(str(table))
$ ~/python/tabletest
col1 col2
row1, col1 row1, col2
$ ~/python/tabletest --boom
Traceback (most recent call last):
File "/home/jpfuntne/python/tabletest", line 21, in <module>
table.add('row2, col1')
File "/home/jpfuntne/repos/fun/table.py", line 719, in add
self.root.append({name: str(row[pos]) for (pos, name) in enumerate(self.headings)})
File "/home/jpfuntne/repos/fun/table.py", line 719, in <dictcomp>
self.root.append({name: str(row[pos]) for (pos, name) in enumerate(self.headings)})
IndexError: tuple index out of range
$
I don't know if this happens when you try to add a row that has more columns.
I'm not saying the class needs to pad or truncate columns when a row doesn't match the headings but the class should handle the situation better and make it clear that the number of columns is not correct.
The text was updated successfully, but these errors were encountered:
pfuntner
pushed a commit
to pfuntner/fun
that referenced
this issue
Jan 3, 2020
I found a bug when the
Table
class oftable.py
when you try to add a row with less columns than the number of headings:I don't know if this happens when you try to add a row that has more columns.
I'm not saying the class needs to pad or truncate columns when a row doesn't match the headings but the class should handle the situation better and make it clear that the number of columns is not correct.
The text was updated successfully, but these errors were encountered: