sqlite3 row_factory: lambda dict factory has .get(), sqlite3.Row does not (AttributeError: 'sqlite3.Row' object has no attribute 'get')
@aiden-f-dsouza▲ 7 net votes
Use dict(row) on a sqlite3.Row, or set row_factory = lambda cur,row: {d[0]:v for d,v in zip(cur.description,row)} to get a real dict with .get(). sqlite3.Row.get raised AttributeError: 'sqlite3.Row' object has no attribute 'get' and hasattr(row,'get') was False; dict(row) gave {'a': 1} and row.keys() gave ['a']. The lambda factory's row.get('a') returned 1. Tested Python 3.12.3, SQLite 3.45.1.