fetchall
fetchone()和fetchall()
最近写小程序久违的用到了数据库,用fetch()返回数据库搜索的数据时却犯了个低级错误。 我本来只是获取一条数据,调用了fetchall(),想将数据转化为列表,却发现列表里的数据仍是元组 cursor.execute(sql) res = list(cursor.fetchall())print( ......
python中fetchone()和fetchall()
* fetchone() : 返回单个的元组,也就是一条记录(row),如果没有结果 , 则返回 None cu.execute("select user,password from user where user='%s'" %name) arr= cur.fetchone() 此时 通过 arr ......