gpt4 book ai didi

Python 到 SQLite3

转载 作者:太空宇宙 更新时间:2023-11-04 05:40:57 25 4
gpt4 key购买 nike

我正在制作一个项目,我在其中使用 Python 连接到数据库,然后更新和更改内容。我在尝试检索信息时遇到了问题。

我正在使用这段代码:

import sqlite3
conn = sqlite3.connect('Project.db')

print ("Opened database sucessfully")

cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")
for row in cursor:
print ("ID = "), row[0]
print ("ResidentTitle ="), row[1]
print ("Name ="), row[2]

print ("done");
conn.close()

从这里我得到了错误:

Traceback (most recent call last):
File "C:/sqlite/Sqlplz.py", line 7, in <module>
cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")
sqlite3.OperationalError: no such table: Residents

我该如何解决这个错误?

最佳答案

cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROMResidents")
-------------------------------------------------------------------^

你缺少空间,你应该这样更新

cursor = conn.execute("SELECT ID,ResidentTitle,ResidentForname FROM Residents")

关于Python 到 SQLite3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33921554/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com