How can I reference columns by their names in python calling SQLite?
问题 I have some code which I've been using to query MySQL, and I'm hoping to use it with SQLite. My real hope is that this will not involve making too many changes to the code. Unfortunately, the following code doesn't work with SQLite: cursor.execute(query) rows = cursor.fetchall() data = [] for row in rows data.append(row["column_name"]) This gives the following error: TypeError: tuple indices must be integers Whereas if I change the reference to use a column number, it works fine: data.append