【问题标题】:How do you assign a variable to a specific cell?如何将变量分配给特定单元格?
【发布时间】:2019-05-06 22:34:48
【问题描述】:

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

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

【问题讨论】:

标签: python sql sqlite


【解决方案1】:

只过滤特定用户并更新

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()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-14
    • 1970-01-01
    • 1970-01-01
    • 2017-06-22
    • 2018-12-23
    相关资源
    最近更新 更多