MODE | MEANING | STREAM POSITION | COMMENT |
---|---|---|---|
r | reading | beginning of the file | default |
r+ | reading and writing | beginning of the file | |
w | writing only | Overwrites / creates a new file for writing | |
w+ | writing and reading | Overwrites / creates a new file for reading and writing | |
rb | reading in binary | beginning of the file | |
rb+ | reading and writing binary | ||
wb+ | writing and reading binary | Overwrites / creates a new file for reading and writing | |
a | appending | end of the file if exists | If the file does not exist, it creates a new file for writing. |
ab | appending in binary | end of the file if exists | If the file does not exist, it creates a new file for writing. |
a+ | appending and reading | end of the file if exists | If the file does not exist, it creates a new file for reading and writing |
ab+ | appending and reading in binary | end of the file exists | If the file does not exist, it creates a new file for reading and writing. |
x | exclusive creation | failing if the file already exists (Python 3) |
Created
February 5, 2022 07:01
-
-
Save pkutaj/3d2b486d9b7b9125ffe8ee9136a231df to your computer and use it in GitHub Desktop.
The-Twelve-Modes-of-Python-File-Handling.md
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment