-3
我認爲我有正確的想法來解決這個功能,但我不確定爲什麼當我測試它時會出現這個錯誤。任何人都可以幫我解決這個問題嗎?返回一個包含位置的數據庫
錯誤:CONN = sqlite3.connect(分貝) sqlite3.OperationalError:無法打開數據庫文件
所需的輸出:
>>> get_locations(db, 'ANTA01H3F')
[( 'ANTA01H3F', 'LEC01',「AA112 '),(' ANTA01H3F」, 'LEC01', 'SY110'),( 'ANTA01H3F', 'LEC02', 'AC223')]
def get_locations(db, course):
'''Return the course, section and locations of the exam for the given course.'''
return run_query('''SELECT Courses.Course, Courses.Sections, Room.Locations
FROM Courses JOIN Locations ON Courses.ID = Locations.ID WHERE Course = ?''', [course])
我run_query功能工作正常,我打電話,但我不知道爲什麼它不工作。 – dg123
高清run_query(DB,Q,ARGS =無): 「」 「(STR,STR,元組) - >元組的列表 返回運行查詢q的結果與 數據庫DB參數ARGS。」 「」 conn.cursor() cur = conn.cursor() #執行查詢時給定的參數傳遞 #如果參數是無,我們只有一個查詢 如果args是None: cur.execute(q ) 否則: cur.execute(q,參數) 結果= cur.fetchall() cur.close() conn.close() 返回結果 – dg123
然後你通過錯誤的論點。讓我糾正它。 – KiranM