This tutorial could not be loaded.
Loading tutorial...
Interactive tutorial
Learn to read and write text files, manage file resources safely, and handle Python exceptions without hiding failures. Build a local score-reporting script that validates rows, reports rejected data, distinguishes data errors from file errors, and produces a summary only after successful input processing.
Step 1 of 10
2 min
Locate Files in a Local Workspace
Set up a local score-tracking workspace and learn how relative Path objects use the working directory.
Step 2 of 10
3 min
Read Text with a Context Manager
Read a small UTF-8 text file with a context manager, observe what `read()` returns, and separate automatic file closure from exception recovery.
Step 3 of 10
3 min
Process Text One Line at a Time
Process a text file one physical line at a time, clean rows intentionally, and preserve accurate source line numbers when blank lines are skipped.
Step 4 of 10
3 min
Write, Append, or Create Exclusively
Choose text file modes for replacement, appending, and protected first-time creation, while writing complete lines explicitly.
Step 5 of 10
3 min
Diagnose and Catch File Errors
Learn to read tracebacks and handle anticipated file failures with specific Python exceptions.
Step 6 of 10
4 min
Control Success, Failure, and Cleanup
Use specific handlers, `else`, and `finally` to make success, failure, and cleanup paths explicit without hiding errors.
Step 7 of 10
4 min
Raise Clear Validation Errors
Build a focused `parse_score(text)` function that separates integer conversion from score-range validation and signals invalid data with `ValueError`.
Step 8 of 10
4 min
Recover from Invalid Rows, Not Broken Reads
Recover from invalid score rows while allowing genuine file-reading failures to propagate honestly.
Step 9 of 10
4 min
Generate a Report with Separate Error Boundaries
Format processed score data and use separate boundaries for input file-level errors and output file-level errors.
Step 10 of 10
7 min
Build and Check the Complete Score Reporter
Integrate, run, and verify the complete local score-reporting script across normal, invalid-data, empty-input, missing-input, and output-failure cases.
Video Courses
recommended
recommended
Advanced
Advanced
Advanced
Ideal for beginners
Ideal for beginners
Thousands of online courses in video, ebooks and audiobooks.
To test your knowledge during online courses
Generated directly from your cell phone's photo gallery and sent to your email
Download our app via QR Code or the links below:.
+ 10 million
students
Free and Valid
Certificate
60 thousand free
exercises
4.8/5 rating in
app stores
Free courses in
video and ebooks