If you don’t read the original file, it will always write a new dictionary.
You have to, at the beginning of the execution of your program, read the file that is on the disk to a dictionary in memory, work with it, update, etc...and at the time of terminating the program, write the dictionary on the disk.
This dictionary on disk will always be a new dictionary created from scratch. Do you have ways to not rewrite everything? It has - but absolutamnte is not worth it. A dictionary with 10000 names will be written in a time around 1 second on the disk, and the complications to keep everything synchronized would be several.
The alternative to this stream of reading everything to memory, working and writing back is to use a database - be it traditional SQL (and Python comes with sqlite, you don’t need to install or configure anything), be it a simpler Nosql database like redis - which works almost like a dictionary "alive".
Now, one thing you’ll need to do is group your code into function . You’ve probably already learned about them, so it’s time to start exercising what you’ve learned. Having a function that reads the dictionary and one that writes the dictionary in the file, you can do it anytime you want, with just one line of code. Da'i the rest of the application can grow to have student inclusion menus, change grades, etc.... and you only need to call the function that records the dictionary, with the whole code in one place.
I tried to use this way with copy but still it writes on top of the already saved txt file.
– Mauro