I'm writing a maths quiz I'm now trying to alter my program so that when my program is run and if the students name is already present in the text file where the scores are saved then it should just add to their scores to the end of theat line where the name is. My program looks like this:
from collections import deque
filename = (str(class_number) + 'txt')
with open(filename, 'a') as f:
for line in f:
if name not in f:
f[name] = deque(maxlen=3)
temp_q = filename[name]
temp_q.append(str(score))
filename[name] = temp_q
else:
with open(filename, 'a') as f:
f.write(str(name) + " : " + str(score) + '\n')
with open(filename) as f:
lines = [line for line in f if line.strip()]
lines.sort()
However I am getting this error:
if name not in f:
UnsuportedOperation: Not readable
Aucun commentaire:
Enregistrer un commentaire