当前位置:Gxlcms > 数据库问题 > python sqlite中通过字段名获取查询结果

python sqlite中通过字段名获取查询结果

时间:2021-07-01 10:21:17 帮助过:2人阅读

sqlite3 con = sqlite3.connect("mydb") con.row_factory = sqlite3.Row cur = con.cursor() cur.execute("select name_last, age from people") for row in cur: assert row[0] == row["name_last"] assert row["name_last"] == row["nAmE_lAsT"] assert row[1] == row["age"] assert row[1] == row["AgE"] #何问起 hovertree.com

 

MySQLdb的实现方法是: 
conn=MySQLdb.connect(..., cursorclass=MySQLdb.cursors.DictCursor) 
或者用MySQLdb.cursors.SSDictCursor。前者数据存储在客户端,后者数据存储在服务器。

推荐:http://www.cnblogs.com/roucheng/p/pythonstring.html

python sqlite中通过字段名获取查询结果

标签:

人气教程排行