By the end of this module you can do everything below. The objectives and their wording come from the official PCEP-30-03 syllabus.
5.1.1 Work with text files
- Open text files using appropriate modes, including
r,w, anda. - Read data from a text file.
- Write and append data to a text file.
- Use the
withstatement to manage file access safely. - Recognize common errors when opening or accessing files.
5.1.2 Work with CSV files
- Explain the basic structure of a CSV file.
- Import and use the
csvmodule. - Read CSV data using
csv.reader(). - Write CSV data using
csv.writer(). - Process rows and values read from a CSV file.