在mysql中有原生提供的字典形式的游标,但是在sqlite3中并没有这样的游标
cursor= connect.cursor(pymysql.cursors.DictCursor
)
但是在Python的官方文档中已经留有响应的实现方案
|
把这个函数代替conn.raw_factory属性即可。
connect = sqlite3.connect("firstsqlite.db")#连接数据库 connect.row_factory = dict_factory cursor = connect.cursor() cursor.execute("""SELECT * FROM student""") sql_list = cursor.fetchall() print(sql_list) 以上就是一个新生博主为大家带来的Python Sqlite3以字典形式返回查询结果的实现方法全部内容了,希望大家多多支持
另附上官方文档链接:https://docs.python.org/2/library/sqlite3.html#sqlite3.Connection.row_factory