我使用python和sqlite3在for 3循环中遇到了这个错误
我不知道如何解决这个问题。。我到处找了,但没找到什么 我犯了这个错误我使用python和sqlite3在for 3循环中遇到了这个错误,python,sqlite,Python,Sqlite,我不知道如何解决这个问题。。我到处找了,但没找到什么 我犯了这个错误 File "D:/python project/master_an1/frontend.py", line 176, in top3_grouped for row3 in database.selecttopstudents(row,row2): File "D:\python project\master_an1\backend.py", line 64, in selecttopstudents se
File "D:/python project/master_an1/frontend.py", line 176, in top3_grouped
for row3 in database.selecttopstudents(row,row2):
File "D:\python project\master_an1\backend.py", line 64, in selecttopstudents
self.cur.execute("SELECT nume,prenume,media FROM student WHERE an=? AND facultate=? ORDER BY media LIMIT 3", (faculty,year))
sqlite3.InterfaceError: Error binding parameter 0 - probably unsupported type.
我有这个密码
def top3_grouped(self):
self.list2.delete(0, END)
for row in database.selectfaculty():
self.list2.insert(END, row)
for row2 in database.selectyear(row):
self.list2.insert(END, row2)
for row3 in database.selecttopstudents(row,row2):
self.list2.insert(END, row3)
def selectfaculty(self):
self.cur.execute("SELECT facultate FROM student GROUP BY facultate")
rows = self.cur.fetchall()
return rows
def selectyear(self,faculty):
self.cur.execute("SELECT an FROM student WHERE facultate=? GROUP BY an", faculty)
rows = self.cur.fetchall()
return rows
def selecttopstudents(self, faculty,year):
self.cur.execute("SELECT nume,prenume,media FROM student WHERE facultate=? AND an=? ORDER BY media LIMIT 3", (faculty,year))
rows = self.cur.fetchall()
return rows
如果我删除了第三行,那么第3行只在两个参数的情况下才能正常工作,为什么会出现这个错误?年份是整数,教员是文本
当我运行应用程序时,显示第一个单词。。
年份是整数,教员是文本
您将行和行2作为参数传递给selecttopstudents,这些项不是文本和整数
这些值来自selectfaculty和selectyear,您没有向我们显示它们,但它们可能是表中的整行
不能将整行对象传递给只需要一个列值的函数
您只需要从这些行中提取教员和年份值,然后使用这些值——也许是这样的
for row3 in database.selecttopstudents(row['faculty'], row2['year']):
我想你把参数的顺序颠倒了,应该是年,faculty@TomNash我现在就试过了,但还是出现了同样的错误。我已经编辑了这篇文章,如果我使用你的sintax,我会使用selectfaculty和selectyear函数。我在数据库的第3行遇到了这个错误。selecttopstudentsrow['facultate',第2行['an']:TypeError:元组索引必须是整数或切片,而不是strOMG。选择TopStudentsRow[0],row2[0]:我使用索引而不是str