Oct-28-2020, 10:46 PM
What I'm doing is making a big excel with all the students homework answers in each row. The first 2 columns are name and student number.
My goal is to make a MySQL table with all the students' answers, so they can click a button and see their answers and the correct answers. Eventually, I will do everything on the webhost in MySQL and stop downloading files.
A typical file is a text file with a name composed of:
The times are so each submission will have a different name, in case a student submits more than 1 time.
The content is like this, just longer:
Yesterday, I did this below. Can anyone see anything wrong with it?
When I checked the dictionary studentAnswers, the keys were all different, but the values were all the same.
The value was always a list of the answers in the last file in the list of files weekXfiles. The student number was 1925010310. FOR EVERY KEY!
I can't understand what is wrong, apart from thinking there is a bug in my Python installation, or in Idle.
weekXfiles is a list of all files from 1 particular week, like 19BEwW3
In the end I avoided using a dictionary and just made a list and wrote it directly to excel. That worked.
My goal is to make a MySQL table with all the students' answers, so they can click a button and see their answers and the correct answers. Eventually, I will do everything on the webhost in MySQL and stop downloading files.
A typical file is a text file with a name composed of:
Quote:studentnumber_COURSEweek_microtime epochtime like this: 1925010101_19BEwW3_0.74946700 1600771500
The times are so each submission will have a different name, in case a student submits more than 1 time.
The content is like this, just longer:
Quote:Studentnr = 1925010101These are written to my webpage by PHP, I download them and mark them.
B
B
C
A
Yesterday, I did this below. Can anyone see anything wrong with it?
When I checked the dictionary studentAnswers, the keys were all different, but the values were all the same.
The value was always a list of the answers in the last file in the list of files weekXfiles. The student number was 1925010310. FOR EVERY KEY!
I can't understand what is wrong, apart from thinking there is a bug in my Python installation, or in Idle.
weekXfiles is a list of all files from 1 particular week, like 19BEwW3
studentAnswers = {} studentAnswersList = [] for hw in weekXfiles: studentAnswersList.clear() data = open(pathHW + hw, 'r') dataList = data.readlines() data.close() name = hw[21:] for i in range(0, len(dataList)): studentAnswer = dataList[i].replace('\n', '') studentAnswersList.append(studentAnswer) studentAnswers[name] = studentAnswersListI do the same kind of thing often, for example, for marking: use the student number as key and the score as value, make a dictionary, then read it into excel. Never had this problem.
In the end I avoided using a dictionary and just made a list and wrote it directly to excel. That worked.