AQA Computer Science NEA 2020 draftWatch
Have a look at some of these to explain file handling:
The easiest way to work with files is to do all the 'read' logic at once and get all of that file's contents/data into a list in one go, because then you don't need to write any logic which messes about with files, instead doing everything in the program's memory using a list.
If you do that, when it comes to saving/updating the file, you can just overwrite the whole file by cycling through the whole list.
The reason for doing that is files only allow you to read/write sequentially, so that puts a lot of very difficult limitations on what you can do with a file. Lists are a lot more versatile, so if you build all the logic around lists and only interact with the physical files by doing 'read all' or 'write all' then it makes everything a lot easier.
Its good to write separate functions which Read and Write to/from the list as well, because then you can use them at any time. keeping the file read/write logic separate from the rest of the program, which is much easier to use. It avoids cluttering up the rest of the program with file read/write logic too.