https://github.com/python/cpython/blame/main/Doc/library/functions.rst#L1190
Modes
'w+'
and'w+b'
open and truncate the file.
Is it right? I thought that the +
means exactly that it does NOT truncate the file. Doesn’t it?
https://github.com/python/cpython/blame/main/Doc/library/functions.rst#L1190
Modes
'w+'
and'w+b'
open and truncate the file.
Is it right? I thought that the +
means exactly that it does NOT truncate the file. Doesn’t it?
You want a+
to not truncate.
This is the same as the C fopen()
function. See e.g.: fopen, fopen_s - cppreference.com (or man 3 fopen
if you’re using a Unix variation).
One may need “r+” or “r+b” instead if there’s a need to write to arbitrary offsets in the file. Append mode always writes to the end of the file.