2.9.1.7 File Modes
Python Programming
File modes specify the operations that can be performed on a file, such as reading, writing, or appending.
- Read (r): Opens a file for reading only. The file must exist.
- Write (w): Opens a file for writing only. If the file exists, it truncates the file. If it does not exist, it creates a new file.
- Append (a): Opens a file for appending. Data written to the file is added to the end of the file.
- Read and Write (r+): Opens a file for both reading and writing. The file must exist.