我正在尝试向我的程序中添加一项功能,以使老师可以根据他们所创建的课程为用户设置作业。有一个用户表,其中每个用户都有唯一的UserID,类名,名字和姓氏。我正在尝试获取特定班级学生的用户ID,并将其插入HomeworkSet表中。我能够成功检索到用户ID,但是当我将它们插入到HomeworkSet表中时,这些值将显示为(例如)(“ 2a1910e919a84230bfc2a7111160cade”),并且我不确定如何删除括号和撇号。
def Class_sethw():
homeworktoset = Homework_To_Set.get()
#print (homeworktoset)
conn = sqlite3.connect('MyComputerScience.db')
c = conn.cursor()
homeworkID = c.execute("SELECT HWID FROM HomeworkInfo WHERE HomeworkName = ?", (homeworktoset, )).fetchone()
print (homeworkID)
c.execute("SELECT UserID FROM users WHERE ClassName = ?", (ClassName_SetHWR, ))
homeworksetlist = c.fetchall()
print (homeworksetlist)
for i in (homeworksetlist):
#x = i
#firstname, lastname = x.split(" ")
c.execute('insert INTO HomeworkSet (HWID, StudentID)VALUES(?,?);', ((homeworkID[0]), str(i)))
conn.commit()
Label(sethw, text = "Homework Set!", fg = "GREEN").place(relx=0.205, rely=0.445, height=34, width=97)
这是我使用的代码。
答案 0 :(得分:0)
您应该更改此行:
for i in (homeworksetlist):
收件人:
for i in homeworksetlist: