Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File Modes table seems incomplete #18

Open
th3ragex opened this issue May 6, 2019 · 0 comments
Open

File Modes table seems incomplete #18

th3ragex opened this issue May 6, 2019 · 0 comments

Comments

@th3ragex
Copy link

th3ragex commented May 6, 2019

Hi, I found this tiny python summary very helpful for catching up with the language.

During an online course I stumbled upon the file modes of the 'open()' method. The "r+" and "w+" file modes seem to be missing in this book. The only "+" mode which is mentioned is "w+b".

I think adding the "r+", "w+", "rb+", "a+" and "ab+" modes would be helpful. (Especially the difference between "r+" and "w+" is not obvious.)

From python help:

`
========= ====
Character Meaning


'r' open for reading (default)
'w' open for writing, truncating the file first
'x' create a new file and open it for writing
'a' open for writing, appending to the end of the file if it exists
'b' binary mode
't' text mode (default)
'+' open a disk file for updating (reading and writing)
'U' universal newline mode (deprecated)
========= ====`

From: https://stackoverflow.com/a/23566951
`

r          Opens a file for reading only. The file pointer is placed at the beginning of the file. This is the default mode.
rb        Opens a file for reading only in binary format. The file pointer is placed at the beginning of the file. This is the default mode.
r+        Opens a file for both reading and writing. The file pointer will be at the beginning of the file.
rb+        Opens a file for both reading and writing in binary format. The file pointer will be at the beginning of the file.
w        Opens a file for writing only. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.
wb        Opens a file for writing only in binary format. Overwrites the file if the file exists. If the file does not exist, creates a new file for writing.
w+        Opens a file for both writing and reading. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing.
wb+        Opens a file for both writing and reading in binary format. Overwrites the existing file if the file exists. If the file does not exist, creates a new file for reading and writing.
a        Opens a file for appending. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
ab        Opens a file for appending in binary format. The file pointer is at the end of the file if the file exists. That is, the file is in the append mode. If the file does not exist, it creates a new file for writing.
a+        Opens a file for both appending and reading. The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing.
ab+        Opens a file for both appending and reading in binary format. The file pointer is at the end of the file if the file exists. The file opens in the append mode. If the file does not exist, it creates a new file for reading and writing.

`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant