Skip to content

Commit 5534b57

Browse files
committed
accept PEP 0249 cursor objects as data to be tabulated
1 parent c300cdf commit 5534b57

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

tabulate.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -747,6 +747,11 @@ def _normalize_tabular_data(tabular_data, headers, showindex="default"):
747747
raise ValueError('headers for a list of dicts is not a dict or a keyword')
748748
rows = [[row.get(k) for k in keys] for row in rows]
749749

750+
elif headers == "keys" and hasattr(tabular_data, "description"):
751+
# Python Database API cursor object (PEP 0249)
752+
# print tabulate(cursor, headers='keys')
753+
headers = [column[0] for column in tabular_data.description]
754+
750755
elif headers == "keys" and len(rows) > 0:
751756
# keys are column indices
752757
headers = list(map(_text_type, range(len(rows[0]))))

0 commit comments

Comments
 (0)