在这种情况下,我有一个简单的用户数据库来记录用户名和密码。
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
答案 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()