Dec-06-2020, 12:01 AM
(This post was last modified: Dec-06-2020, 12:01 AM by Pedroski55.)
Whoops, put the wrong title! That was another thing I was trying.
I have a simple homework webpage.
PHP collects the students answers, compares them with the correct answers and marks them.
Then the score is written to a MySQL table against that student's student number.
All I have to do is export the columns student_nr and score each week from the results table and I have all the results in a csv file.
I save the csv as an Excel, then Python takes over. I open the excel file and read the student number as key and the score as value into a dictionary: studentsScores
Now I read the scores into a blanko results file containing all the students' numbers in column 1
For each student, I run through all the keys, 163 * 163. (Just for this course)
Can that be done quicker? (Not that this takes more than a second, but I'm just wondering if there is another, better way)
I am reading a book from Reuven Lerner, Python Workout, he has some neat tricks!
I have a simple homework webpage.
PHP collects the students answers, compares them with the correct answers and marks them.
Then the score is written to a MySQL table against that student's student number.
All I have to do is export the columns student_nr and score each week from the results table and I have all the results in a csv file.
I save the csv as an Excel, then Python takes over. I open the excel file and read the student number as key and the score as value into a dictionary: studentsScores
Now I read the scores into a blanko results file containing all the students' numbers in column 1
# put HW scores in the results file for key in studentScores.keys(): try: for rowNum in range(2, blankoFilerows + 1): if str(key) == str(blankoFile[clas].cell(row=rowNum, column=1).value): blankoFile[clas].cell(row=rowNum, column=4, value=studentScores[key]) except KeyError: passI am just wondering, is there a more "Pythonic", more elegant and quicker way to do this?
For each student, I run through all the keys, 163 * 163. (Just for this course)
Can that be done quicker? (Not that this takes more than a second, but I'm just wondering if there is another, better way)
I am reading a book from Reuven Lerner, Python Workout, he has some neat tricks!