简体   繁体   English

AttributeError:对象没有属性'execute'

[英]AttributeError: object has no attribute 'execute'

I get this error whenever I run my program. 每当我运行程序时,我都会收到此错误。

Traceback (most recent call last):
  File "C:/Users/Shepard/Desktop/Gradebook.py", line 51, in <module>
    qs.CreateDb()
  File "C:/Users/Shepard/Desktop/Gradebook.py", line 14, in CreateDb
    self.cursor.exeute(query)
AttributeError: 'sqlite3.Cursor' object has no attribute 'exeute'

This makes me beleive that my problems are in: 这使我相信我的问题在于:

 def CreateDb(self):
        query = """CREATE TABLE questions
                 (id INTEGER PRIMARY KEY, Question TEXT, Answer1 TEXT, Answer2 TEXT, Answer3 TEXT, Answer4 TEXT, CorrectAnswer TEXT)"""
        self.cursor.exeute(query)
        self.connection.commit()
        self.cursor.close()

either in that, or in 无论是在那个,还是在...

def AddQuestion(self, Question, Answer1, Answer2, Answer3, Answer4):
    self.cursor.execute("""INSERT INTO questions
                        VALUES (?, ?, ?, ?, ?, ?)""", [None, Question, Answer1, Answer2, Answer3, Answer4, CorrectAnswer])
self.connection.commit()

Is 'execute' not a valid attribute? “执行”不是有效属性吗? If so, what should I use? 如果是这样,我应该使用什么? I'm a little over my head in this one. 我在这一点上有点过头了。 :P :P

It' doesn't say "execute" it says "exeute". 它没有说“执行”它说“执行”。 You misspelled it. 你拼错了。

There word 'exeute' in your function for CreateDB, 你的CreateDB函数中有'exeute'字样,

self.cursor.exeute(query)

it should be 'execute'. 它应该是'执行'。 I have made the same mistake. 我犯了同样的错误。

This will show you the possible commands for both the connection and cursor: 这将显示连接和光标的可能命令:

print("Connection functions:",dir(sqlite3.connect('::memory::')))
print("\n\n")
print("Cursor functions:",dir(sqlite3.connect('::memory::').cursor()))

Check that things are spelled right and that you don't mix connection and cursor. 检查事情拼写正确,并且不要混合连接和光标。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM