|
各位前辈,本人刚接触python, 在做练习时,有一个问题思考半天不知怎么解决,百度很久也没搞明白,请高人指点一二,不胜感激。pytho3在连接sqlite数据库,查询所有内容以后,想把内容打印成表的形式,但是一直报错,打印部分代码如下:
try:
cur.execute(sql)
# 获取所有数据
info_list = []
info_all = cur.fetchall()
info_list.append(info_all)
for p in info_list:
#print(info_list)
print("%s\t\t'%s'\t\t%s\t\t%s\t\t'%s'\t\t" % (p["pid"], p["name"], p["phone"], p["qq"], p["email"]))
except Exception as e:
print(e)
print('查询失败')
报错:list indices must be integers or slices, not str
查询失败
我在这里先谢谢各位了
|
|