Python open built-in function: difference between modes a, a+, w, w+, and r+?

1.5K    Asked by alexGONZALEZ in Python , Asked on Mar 3, 2021
Answered by alex GONZALEZ

w: Opens in write-only mode. The pointer is placed at the beginning of the file and this will overwrite any existing file with the same name. It will create a new file if one with the same name doesn't exist.


a: Opens a file for appending new information to it. The pointer is placed at the end of the file. A new file is created if one with the same name doesn't exist.

w+: Opens a file for writing and reading.

a+: Opens a file for both appending and reading.

r+: Opens a file for reading and writing, placing the pointer at the beginning of the file.



Your Answer

Interviews

Parent Categories