Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 511dea0

Browse files
authored
GH-95880: Clarify StringIO append/overwrite behavior. (GH-96104)
1 parent 0e28a3a commit 511dea0

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Doc/library/io.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,8 +1052,12 @@ Text I/O
10521052

10531053
The initial value of the buffer can be set by providing *initial_value*.
10541054
If newline translation is enabled, newlines will be encoded as if by
1055-
:meth:`~TextIOBase.write`. The stream is positioned at the start of
1056-
the buffer.
1055+
:meth:`~TextIOBase.write`. The stream is positioned at the start of the
1056+
buffer which emulates opening an existing file in a `w+` mode, making it
1057+
ready for an immediate write from the beginning or for a write that
1058+
would overwrite the initial value. To emulate opening a file in an `a+`
1059+
mode ready for appending, use `f.seek(0, io.SEEK_END)` to reposition the
1060+
stream at the end of the buffer.
10571061

10581062
The *newline* argument works like that of :class:`TextIOWrapper`,
10591063
except that when writing output to the stream, if *newline* is ``None``,

0 commit comments

Comments
 (0)