Use Python’s built-in open function to connect to a file and obtain a file object for reading, writing, appending, or binary operations. The object exposes the file name, mode, encoding, and methods for processing its contents. section 11.1.1
Read a task file safely
Prefer a context manager so the file is released automatically: with open("tasks.txt") as file: data = file.read() print(data) The default mode is read text mode. After the with block, the file is closed. section 11.1.1
Choose the mode according to the operation:
- "r" reads an existing file; omitting the mode uses read mode. section 11.1.1
- "w" writes a new file or replaces an existing file; use write methods such as write or writelines. section 11.1.3
- "a" appends data at the end of an existing file. section 11.1.3
- "wb" opens a binary file for writing, as required when pickle.dump preserves Python objects. section 11.3.1








