Skip to content

Commit 86bcf75

Browse files
committed
database cursor detection: also check for .rowcount and .fetchone
1 parent ce2a3db commit 86bcf75

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

tabulate.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -747,7 +747,10 @@ 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"):
750+
elif (headers == "keys"
751+
and hasattr(tabular_data, "description")
752+
and hasattr(tabular_data, "fetchone")
753+
and hasattr(tabular_data, "rowcount")):
751754
# Python Database API cursor object (PEP 0249)
752755
# print tabulate(cursor, headers='keys')
753756
headers = [column[0] for column in tabular_data.description]

0 commit comments

Comments
 (0)