如何将变量分配给特定的单元格?

时间:2019-05-06 22:34:48

标签: python sql sqlite

在这种情况下,我有一个简单的用户数据库来记录用户名和密码。

def load(*args):
options = {"level":0, "age":1, "cname":2, "reputation":3, "cl":4}
con = lite.connect(FILE)
with con:
    cur = con.cursor()
    cur.execute("SELECT * FROM data")

    while True:
        row = cur.fetchone()
        if row == None:
            break

        for i in args:
            if i in options.keys():
                indices = []
                val = options.get(i)
                print(val)
                indices.append(row[0][val])
return indices

这是从sqlite数据库返回一个特定的单元格;我收到的错误是:

    indices.append(row[0][val])
    IndexError: string index out of range

1 个答案:

答案 0 :(得分:0)

只需过滤特定用户并更新

import sqlite3
conn = sqlite3.connect("user.db")
c = conn.cursor()
pwd = 'hfrhbx63784hjf53hu&5'
user ='Nick'
c.execute(f"update users set password = '{pwd}' where name ='{user}'")
conn.commit()
相关问题