📅  最后修改于: 2022-03-11 14:45:24.495000             🧑  作者: Mango
def dict_factory(cursor, row):
d = {}
for idx, col in enumerate(cursor.description):
d[col[0]] = row[idx]
return d
conn = sqlite3.connect("data.db")
conn.row_factory = dict_factory
db = conn.cursor()
print(db.execute("SELECT * FROM table"))
>>> [{'col1': 'val1', 'col2': 'val2'}, {'col1': 'val3', 'col2': 'val4'}]