我的代码开头是:
import sqlite3
def construct_query(card_name, card_type,card_type_whole, power, tough, card_text, exp,rare):
query = "INSERT INTO CardComponet (all column names) VALUES ('{}','{}',{},{},'{}','{}','{}')".format(card_name, card_type_whole, power, tough, card_text, exp,rare)
return query
path_to_flat_file = 'C:\Users\Mrs Rose\Desktop\inputf.txt'
flat_file_object = open(path_to_flat_file, 'r')
connection = sqlite3.connection('practice1.db')
cursor = connection.cursor()
但我的错误是:
^{pr2}$我尝试更改我的.py名称和我的数据库名称,但没有任何效果。如果可以,请帮忙。在
sqlite3模块没有名为“connection”的属性,但有一个名为connect的属性。您应该尝试“connection=sqlite3.connect('practice1.db')”
sqlite3.connection
不存在。您要查找的函数名为^{另外,您不应该使用
str.format
或类似的工具将值插入到查询中。从docs:我看到了几个可能的错误:
从文件路径看,我猜你在窗口。好吧,您需要更改文件路径:
C:\\Users\\Mrs Rose\\Desktop\\
以避免混淆为转义字符。在我的IDE上,}?
sqlite3
模块没有connection
方法。。也许{相关问题 更多 >
编程相关推荐