現在、テストを作成してデータベースに保存し、印刷できるようにするプログラムに取り組んでいます。エラーが発生し続けます:
Traceback (most recent call last):
File "C:/Users/Shepard/Desktop/Gradebook.py", line 50, in <module>
qs = QuestionStorage("questions.db")
TypeError: object.__new__() takes no parameters
誰でも何か考えがありますか?QuestionStorage クラスのどこかにあると想定していますが、何も理解できません。SQLite3 を使用するのはこれが初めてで、かなりの問題を抱えています。誰かが私を助けてくれれば、それは素晴らしいことです。:)
import sqlite3
class QuestionStorage(object):
def _init_(self, path):
self.connection = sqlite3.connect(path)
self.cursor = self.connection.cursor()
def Close(self):
self.cursor.close()
self.connection.close()
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()
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()
def GetQuestion(self, index = None):
self.cursor.execute("""SELECT * FROM questions WEHRE id=?""", (index,))
res = self.cursor.fetchone()
return res
print ("TestMaker v.1")
print ("To create a multiple choice test, follow the directions.")
testName = input ("Give your test a name.")
testQ = int(input ("How many questions will be on this test? (Numeric value only.)"))
counter = 1
while counter <= testQ:
Answer = []
Answer = [1,2,3,4,5,6]
Question = input ("What is your question?")
Answer[1] = input ("What is the first answer?")
Answer[2] = input ("What is the second answer?")
Answer[3] = input ("What is the third answer?")
Answer[4] = input ("What is your last answer?")
correctAnswer = int(input("Which answer is the correct answer? (1, 2, 3, or 4?)"))
Answer[5] = Answer[correctAnswer]
print (Answer[1:6])
counter +=1
if __name__ == "__main__":
qs = QuestionStorage("questions.db")
qs.CreateDb()
qs.AddQuestion(Question, Answer[1] , Answer[2], Answer[3], Answer[4], Answer[5])
qs.Close()