Python Foundations · Unit 7

Unit 7: Files & Errors

Read and write files, and handle errors without crashing.

  • 2 hrs
  • Intermediate
  • 10 lessons

Lessons

  1. Introduction to File HandlingWhat file handling is, persistent storage, text vs binary files, common use cases 15–20 min
  2. Opening and Closing FilesHow to open files, file modes, how to close files, file objects, common mistakes 20–25 min
  3. Reading Data from FilesReading entire files, reading line by line, iterating through files, common patterns 20–25 min
  4. Writing Data to FilesWriting to files, writing multiple lines, write vs append, formatting output 20–25 min
  5. Working with File PathsRelative vs absolute paths, path joining, the pathlib module, cross-platform compatibility 20–25 min
  6. Using the with Statement for File OperationsThe with statement, why it's better, context managers, multiple files, best practices 15–20 min
  7. Understanding Errors and ExceptionsWhat errors are, types of errors, common exceptions, error messages, why exceptions exist 20–25 min
  8. The try and except Blockstry and except, handling specific exceptions, error messages, else and finally 25–30 min
  9. Raising and Customizing ExceptionsRaising exceptions, when to raise, custom exceptions, error messages, best practices 20–25 min
  10. File and Error Handling in Real ProjectsReal-world patterns, data logging, user input handling, best practices, complete examples 30–40 min
  11. End of unit test

    Ten multiple choice questions worth 7 points each and one free response problem worth 30, so 100 in total. Score 70 or more to finish Unit 7 and unlock Unit 8.

    Take the Unit 7 test