【发布时间】:2010-11-10 18:23:21
【问题描述】:
当我做某事时
sqlite.cursor.execute("SELECT * FROM foo")
result = sqlite.cursor.fetchone()
我认为必须记住列似乎能够提取它们的顺序,例如
result[0] is id
result[1] is first_name
有没有办法返回字典?所以我可以改用 result['id'] 或类似的?
编号列的问题是,如果您编写代码然后插入一列,您可能需要更改代码,例如 first_name 的 result[1] 现在可能是 date_joined,因此必须更新所有代码...
【问题讨论】:
-
How can I get dict from sqlite query? 的可能重复 这是关于 sqlite 还是 mysql?
标签: python mysql sqlite dictionary dataformat