1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#!/usr/bin/env python3
from sys import argv
rows = {}
with open("students.textdb", "rt") as file:
for line in file.readlines():
idx, lab, proj, exam = line.strip().split(" ")
rows[int(idx)] = (idx, lab, proj, exam)
# argv is like
# ["set_student_1.py", "512345", "5.0", "3.0", "3.0"]
rows[int(argv[1])] = tuple(argv[1:5])
with open("students.textdb", "wt") as file:
for _, (idx, lab, proj, exam) in sorted(dict.items(rows)):
# simulate slow disk writes
from time import sleep
sleep(0.15)
print(idx, lab, proj, exam, file=file)
|