我正在使用Python 3.4中的数据库连接.我的数据库中有两列.
下面是查询,它以两种显示的格式QUERY为我提供了所有数据:
cur.execute(""" select * from filehash """)
data=cur.fetchall()
print(data)
Run Code Online (Sandbox Code Playgroud)
OUTPUT:
[('F:\\test1.py', '12345abc'), ('F:\\test2.py', 'avcr123')]
Run Code Online (Sandbox Code Playgroud)
要遍历此输出,我的代码如下所示
cur.execute(""" select * from filehash """)
data=cur.fetchall()
i=0
j=1
for i,row in data:
print(row[i])
print(row[j])
i=i+1
Run Code Online (Sandbox Code Playgroud)
这给了我以下错误
print(row[i])
TypeError: string indices must be integers
Run Code Online (Sandbox Code Playgroud)
让我知道我们如何处理个人价值观 fetchall()