GCSE Python · Lesson 7 of 9Text files and exception handling
OCR J277 2.2 / AQA 8525 programming
Write results to a file, then read and total the values safely.
← All GCSE Python lessons Robust file processing
Programs can write and read text files to preserve simple records. They also need to anticipate missing files and invalid contents. Test both the expected file and an error case so that the program fails gracefully.
Watch out: Catching every exception without explaining the problem can conceal bugs. Catch the specific errors you expect.
A free TutorSyntax programming lesson. About our teaching approach.