[英]I got this error in for 3 loop using python and sqlite3
我不知道該如何解決..我到處搜索,但沒有找到任何東西..
我得到這個錯誤
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
如果我刪除(row3)的第三個參數,只有兩個參數可以完美工作,為什么會出現此錯誤? 年是INTEGER,教師是TEXT
當我運行應用程序時,顯示此單詞。. 單擊查看來自imgur.com的圖像
年是INTEGER,教師是TEXT
您將row
和row2
作為參數傳遞給selecttopstudents()
,這些項目不是文本和整數。
這些值來自selectfaculty()
和selectyear()
,您沒有顯示給我們,但是大概它們是表中的整行。
您不能將整個行對象傳遞給只需要單個列值的函數。
您只需要從這些行中提取教師和年份值,然后使用它們-也許像這樣?
for row3 in database.selecttopstudents(row['faculty'], row2['year']):
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.