Python - File Modes
Last Updated: 0021Z 12FEB20
(Created: 0019Z 12FEB20)
File Modes:
- r : read
- r+ : reading and writing (cannot truncate file)
- rb : for reading a binary file
- rb+ : reading or writing a binary file
- w : for writing, create if doesn't exist
- w+ : for writing and reading (can truncate file)
- wb+ : for writing or reading a binary file
- a : open a file for appending (will create if it doesn't exist)
- a+ : open a file for appending and reading
- ab+ : open a binary file for appending or reading
- x : open for exclusive creation (Python 3). Raises FileExistsError if file exists.
References: